Ever wondered how different sites use Google authentication in order to make your signup/login process a whole lot easier. Well, Google Oauth is something that they use in order to achieve this.

We are going to go step by step about how to apply this in your Node.Js applications using Passport.Js and Express.Js

First of all, making an app.js file in your root directly and starting a server using Express.Js and mongoose to connect to your MongoDB database. In order to do this, you’ll need to install all the npm dependencies. To initialize ‘npm’ in your project use in your terminal:

Project Initialization

npm init

and set all the options as per your wish, I usually keep them in their default state.

Image for post

You should be able to see something like this in your terminal.

After you are done with this NodeJs would create a package.json file for you, where all your dependencies and their versions should be visible.

After that use

npm i express mongoose body-parser dotenv

in order to install all the required dependencies to start a server and connect with MongoDB.

Image for post

#oauth #google #nodejs #passportjs #oauth2

How to Integrate Google Oauth in your Node.Js Applications
3.55 GEEK