Skip to content

mertcb/simple-node-mongo-architecture

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple NodeJS + MongoDB Backend Architecture

This is a clean NodeJS project for beginners. It will make easier to follow your code. Don't forget to star this repo if you've found it useful, maybe it can help newbie developers in nodeJS.

Installation

You can clone this repo and run the npm init command for initializing this repo as a new project.

$ npm init

Installation for all node modules is done using the npm install command:

$ npm install

Usage

After Installation

You must create a .env file after installation and write your environmental variables to this file.

For example

PORT=8000
MONGODB_URI="mongodb://localhost/myProject"
HOST_NAME="localhost"

Don't forget to fill config.js file after adding new environmental variable to .env file.

For example

const config = {
  PORT: process.env.PORT,
  MONGODB_URI: process.env.MONGODB_URI, //your mongodb url
  HOST_NAME: process.env.HOST_NAME // example hostname "localhost"
  NEW_VALUE: process.env.NEW_VALUE
};

After Creating a New Route

When you create a new route, don't forget to import your new route to index.js file. You can do it like below.

import exampleRoute from "./routes/exampleRoute";
.
.
.
.
.
.
app.use(exampleRoute);

Example File/Folder Structure

exampleProject
│   config.js
│   .env   
│   package.json
│   package-lock.json
│
└───src
│   │   index.js
│   │
│   └───data
│       │   db.js
│       │   └───model
│       │       │   exampleModel.js
│       │       │   ...
│       │   └───schema
│       │       │   exampleSchema.js
│       │       │   ...
│   └───routes
│       │   index.js
│       │   exampleRoute.js
│       │   ...
└───node_modules
    │   Node Modules will stored here.

Running the project

$ npm run-script server

License

GNU General Public License

Author

Mert Can Bilgiç (mert@computer.org)

Follow me (@mrtcnblgc17) on Twitter!

About

You can use this repo as preconfigured nodeJS+mongoose project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published