I have created my first project width node, express and mongoose in those days, There is an important part for project which is authentication. So here is my summary in the following.
Quick Start
Install
1 | npm install jsonwebtoken --save |
- express is the popular Node framework
- mongoose is how we interact with our MongoDB database
- morgan will log requests to the console so we can see what is happening
- body-parser will let us get parameters from our POST requests
- jsonwebtoken is how we create and verify our JSON Web Tokens
Config File(config.js)
1 | module.exports = { |
App.js
1 | const express = require("express"); |
Mongoose(config/default.js)
1 | module.exports = { |
Connect mongoose(db.js)
1 |
|
Creating a Sample module
1 | let mongoose = require('mongoose'); |
Create verifyToken.js
1 | var jwt = require('jsonwebtoken'); |
Add router
1 | let express = require('express'); |
Create controller(User.js)
1 | /** |
Create generateToken.js
1 | generateToken: function(userId) { |
More info: