First, we have to know what is JWT? JWT(jsonwebtoken) is npm package which is used to create token when user log-in into our application.

  • the basic structure of token is as below:-
JWT token structure
  • Header:- Header in JWT token contains some metadata about the token. we as users don't have to write anything into it.
  • Payload:- Payload is the information that we have to add to the token for any further use.
  • Signature:- Signature is the URLencoded text which is made using Header, Payload, and Secret available in the server. the same secret is to be used to extract information from tokens…


  • In any express application, we can use PassportJS npm package to authenticate users using 3rd party application.
  • These applications are used to get their public profile data. there are 5 steps to use Github-Strategy for Oauth.
  • But first of all, we have to set up a basic Express server using the express package and set up session middleware to create a session.

Step 1:- Registering the app to Github.

  • First, we have to register our app to our GitHub profile for getting Client_Secret and Client_ID.
  • Go to github>profile>settings>developer Settings>Oauth apps.
  • now click on the new OAuth app and type application name, Home page URL as “http://localhost:3000”, callback…


******** Part 1:-Handling registration part. *******

Step 1:-

  • First, install express-generator and nodemon packages globally into your system.
npm i --global express-generatornpm i --global nodemon

Express-generator”:- this will help you setup basic server

nodemon”:- this will restart your server automatically after you save changes.

  • Now, we can set up a basic express server by just typing:-
express --view=ejs --css=sass <ProjName>
  • Now, for creating Models to store data in MongoDB we have to install the “mongoose ”package.
npm i mongoose --save

Step 2:-

  • Now, we have to create a User model to store data inside MongoDB. we have to create a new folder named “models” at the root. Once done…


1) Handle data inside the body of the request object using “node.JS”: — —

  • First, we have to create a server using node.JS . for this refer link:- “click here to learn how to create a server using node.JS”.
  • Once the server is created, now we have to create a new variable named “data” to store incoming data from the body of the request object.
  • As we know request is also a eventEmitter so here we can use its req.on() method.
  • req.on() also have two methods 1)data 2)end .

1) “data” will be called when data starts coming in small chunks and executes repeatedly until data stops coming.

2) “end” will be called when…


1) How to create a basic server using express in node.JS

  • first, we have to create a package.json file into our project by using the following command:- “npm init
  • after creating the package.json file we have to install express using npm and have to make its entry into the package.json file by using the command as following: “ npm install express - -save ”.
  • now we just have to import the express module by requiring it. after that, we have to create a new variable and store the value returned by express().see in the image below:-
creating basic server
  • once the steps above are done, then we have to call listen to a method…


What is object?

Object is set of “Key” and “Value” Pairs

-Functions and Arrays are also different types of objects in JS

ex:- let obj={name: “onkar”};

obj={“displayName”:function (){console.log(“hello”)}};

Why OOP?

  • Every application in the world is made up of main 2 things:- a)data,b) function and methods
  • for creating any application we need data and functions or methods to work on that data.
  • as the number of functions and overall data increases in our project it gets very hard to add new functions and gets really messy.
  • this problem is solved by OOP. OOP helps us to bundle data and functions together which makes code “easy…


Here we are going to understand how to create a basic server using node.js

  1. First, we have to import “HTTP”, ”URL” and “fs” modules into our .js file to use different methods present in that modules. we can import them as below:-
importing modules

2. after importing those three modules, we have to use “createServer()” method of the HTTP module and have to store it into some variable as below. http.createServer() method accepts a call back function as a parameter in which we have to do all things on the server.

Onkar Shingate

Learning MERN stack developement @altCampus

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store