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.
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
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
};
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);
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.
$ npm run-script server