Skip to content

sayhicoelho/nodejs-restful-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Node.js RESTful API

I have nothing to say yet. This is just a study project.

Setup

Step by step to prepare the environment.

Redis

MongoDB

  • Install MongoDB
  • On Windows, create a folder to store the data files (e.g C:\Program Files\MongoDB\Server\4.0\data)
  • Add extra security by editing the file C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg (Windows) or /etc/mongod.conf (Linux) adding the YAML code bellow:
security:
  authorization: enabled
  • In addition, change the dbPath if your're on Windows:
storage:
  dbPath: C:\Program Files\MongoDB\Server\4.0\data
  • On Windows, add the bin path to Environment Variables

  • Stop the MongoDB service to proceed with the next steps by running sudo service mongod stop (Linux) or net stop MongoDB (Windows)

  • Create the super user to work with all databases. Open a command prompt and type:

$ mongod --dbpath "your_data_path" # this will run the MongoDB service without any security mode (e.g --auth)
  • With previous one running, open another command prompt and type:
$ mongo
$ use admin
$ db.createUser({ user: 'root', pwd: 'password', roles: [ 'root' ] })
  • And lastly, close these two command prompts and restart the MongoDB service

Adding new database

As MongoDB works on top of NoSQL document-oriented database, we do not need to create any database for our application.

Whenever we need to start a new application with its database, we create an user and give to it the dbOwner role. So now, we need to go to the command prompt and type:

$ mongo
$ use admin
$ db.auth('root', 'password')
$ use dbname
$ db.createUser({ user: 'admin', pwd: 'password', roles: [ 'dbOwner' ] })

Usage

  • Run the command npm run worker to start the queue worker with bee-queue
  • Run the command npm run start to start the server with nodemon

License

MIT license.

About

My first Node.js RESTful API.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published