Nodejs: Download
version:- >= v10.16.3
-
Clone the repository and install dependencies
git clone https://github.com/PSPenta/node-express-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 mongoose-aggregate-paginate-v2
For SQL DB install Sequelize package
npm i -S sequelize sequelize-paginate
Sequelize supports multiple dialects for RDBMS One of the following command with respect to database:
npm install --save pg pg-hstore # postgres dialect npm install --save mysql2 # mysql dialect npm install --save mariadb # mariadb dialect npm install --save sqlite3 # sqlite dialect npm install --save tedious # mssql dialect
-
After that, if using Sequelize, create database to complete the DB connection.
-
If you want to use DB migrations, you can use sequelize-cli as a dev dependency
npm install --save-dev sequelize-cli
-
Otherwise if you have all the tables already created and you want to import them all at once, you can use sequelize-auto module
npm install sequelize-auto node src/scripts/createModels.js
-
To run tests
npm test
-
Start the application
npm start
-
To test code against linting standards
npm run lint
- 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.