REST API created in NodeJs using Express for Displaying,Storing,Updating Books Records stored on MongoDB.
- NodeJS (Express)
- Express
npm install --save express
- dotenv
npm install --save dotenv
- mongoose
npm install --save mongoose
- jsonwebtoken
npm install jsonwebtoken
- nodemon
npm install --save-dev nodemon
- First, install all the dependencies using npm install
- Edit package.json
"scripts": {
"start": "nodemon index.js"
}
- Then Create a .env file, and add
USER_NAME: admin
PASSWORD: admin123
ACCESS_TOKEN_SECRET: UNIQUE_KEY
- To create unique key, open terminal and type node, then,
require('crypto').randomBytes(16).toString('hex')
- To start the Server
npm start
- You need to have jwt token to add books, update records, and delete records.
- To get the JWT Token.
- Make a POST Request to /login, which will return accessToken, this will expire in 30 minutes.
- Add Authorization in Header section to make POST Requests.
"authorization": "Bearer ${token}"