Full-Stack Web Development with Vue.js and Node

(singke) #1
Building Authentication with passport.js Chapter 6

To start using this package, let's define it in server.js as well:


const morgan = require('morgan')
const fs = require('fs')
const jwt = require('jsonwebtoken');

Installing passport.js


Just like any other npm package, we can install passport.js by running the following


command:


$ npm install passport --save

On successful installation, you should have those package listed on your package.json as


well:


"nodemon": "^1.14.10",
"passport": "^0.4.0",
"sass-loader": "^6.0.6",

You can also do this by first adding the package to your package.json file and then


running the following command:


$ npm install

Configuring passport


Just like any other node package, we will need to configure the package for passport.js.


In our server.js file, add the following lines of code:


...
const mongoose = require('mongoose');
const cors = require('cors');
const morgan = require('morgan');
const fs = require('fs');
const jwt = require('jsonwebtoken');
const passport = require('passport');

const app = express();
const router = express.Router();
Free download pdf