/node-authentication-jwt-mongodb

A simple and secure implementation of REST API using Node.js and MongoDB with JSON Web Tokens which can be used for user authentication.

Primary LanguageJavaScript

Product Name Screen Shot

                         language vulnerability repo size node version npm version

Simple and secure REST API for User Authentication!

Explore the post »

Report Bug · Request Feature

What's inside this repo?

  1. User signup/registration with Email verification.
  2. User Login.
  3. Forgot password and reset password.
  4. Session management using JWT (JSON Web Tokens).
  5. Bonus: Simple Referral System!

For a more detailed explanation of the code, you can refer to my medium post associated with this project. It is split into two parts.

  • Part I - Build User signup with email verification, forgot password and reset password.

  • Part II - Integrate JWT and Build a Simple Referral System.

Built With

  • Node.js - JavaScript runtime built on Chrome's V8 JavaScript engine.
  • Express.js - Minimal and flexible Node.js web application framework
  • MongoDB - Cross-platform document-oriented database program

Getting Started

To get a local copy up and running follow these simple steps :

Prerequisites

To run this project, you'll need to have the following installed:

You can also use MongoDB Atlas if you prefer.

Installation

  1. Register at SendGrid SendGrid and create an API KEY.

  2. Clone the repo :

    git clone https://github.com/PraneshASP/node-authentication-jwt-mongodb.git
  3. Install dependencies (use sudo if required) :

    npm install
  4. Create .env file and configure :

    MONGO_URI = <MONGODB_URL>
    JWT_SECRET = <SOME_LONG_SECURE_SECRET>
    SG_APIKEY = <SENDGRID_API_KEY>  //For sending emails
  5. Start the server :

    npm start