This is a boiler plate for developing a nodejs application with express. I have used Node 8+
and MongoDB 3.6
to create it. I have also implemented JWT
for token verification, I have created some middlewares or helpers for user authentication.
For API documentation I have used Swagger
.
Mongodb 3.6
:
- Install MonngDB 3.6
Ref:
https://docs.mongodb.com/manual/installation/
NodeJS v8+
Ref:
http://nodejs.org
- Go to project working directory / Project folder
- Execute command
npm install
- After that Run Command
node server.js
- Open
http://localhost:4000
to check that your server is running or not. - To check the documentation Kindly follow the:
http://localhost:4000/swagger
- Install Docker
https://docs.docker.com/install/
- Go to terminal, Run command
cd <Project directory path>
- Run command to create node project build
docker build -t node:8 ./
- To Run node server (Local 4000 port mapping node server 4000 port from container)
docker run -p 4000:4000 node:8
- To Run node server in deamon mode use command
<Parameter -d>
docker run -p 4000:4000 -d node:8
- Open
http://localhost:4000
to check that your server is running or not. - To check the documentation Kindly follow the:
http://localhost:4000/swagger
- Create and .env file in your project directory
- Write enviornment variable like:
NODE_ENV=development
- Use
--env-file ./env
parameter withdocker run
command- Example:
docker run --env-file ./env -p 4000:4000 node:8
- Example:
- To set the
environment
variable for your project, you can use./environment/development.yml
or for development or./environment/production.yml
for production environment. - You can also set the environment using shell command:
export env=development
- To check that
environment
variable is set or not:echo ${env}
I hope it will help you to create your new nodejs project with express using swagger api documentation.