Nodejs: Download
version:- >= v10.16.3
-
Clone the repository and install dependencies
$ git clone https://github.com/PSPenta/node-boilerplate.git $ npm install ( If wants to work with existing version of packages ) $ npm run update:packages ( If wants to work with latest version of packages )
-
To start with database configuration create .env file from referencing the env.example file. For MongoDB install Mongoose package
$ npm i -S mongoose
For SQL DB install Sequelize package
$ npm i -S sequelize
Sequelize supports multiple dialects for DBMS One of the following command with respect to database:
$ npm install --save pg pg-hstore # Postgres $ npm install --save mysql2 $ npm install --save mariadb $ npm install --save sqlite3 $ npm install --save tedious # Microsoft SQL Server
-
To run tests
$ npm test
-
Start the application
$ npm start
- Add environment variables in .env file referencing from env.example file.
- In app.js file require passport.js and the src/services/authServices.js and initialize passport.js.
const passport = require('passport'); require('./src/services/authServices'); passport.initialize();
- To create a JWT token use createToken() from authServices.js which takes object and add it in token.
- To authenticate any routes use passport.authenticate() as middleware on it.
const passport = require('passport');
router.use('/demo', passport.authenticate('jwt', { session : false }), (req, res) => {});
- Please remove this README.md file when working with live project.