Giter Site home page Giter Site logo

tedante / express-jwt-boilerplate Goto Github PK

View Code? Open in Web Editor NEW

This project forked from udz-codes/express-jwt-boilerplate

0.0 0.0 0.0 198 KB

A cookiecutter template to create REST API with ExpressJS and MongoDB, with JWT authentication.

License: MIT License

JavaScript 100.00%

express-jwt-boilerplate's Introduction

ExpressJS REST API Boilerplate

A cookiecutter template to create REST API with ExpressJS and MongoDB, with JWT authentication.

Boilerplate Features:

  • Registration
  • Login
  • JWT authentication
  • Private routes example
  • Schema Validation check (email validation, minimum characters, etc.)
  • Password Encryption
  • MongoDB Database
  • API rate limit

Setup

  1. Clone the project
git clone https://github.com/udz-codes/express-rest-boilerplate.git
  1. Install packages
npm install
  1. Setup environment variables: Create .env file in root of the project and set 3 enviroment variables
PORT = ""

DB_URL = ""

JWT_SECRET = ""

PORT: Port number for local host
DB_URL: MongoDB URL, You can use MongoDB Atlas as database
JWT_SECRET: A random string that will be used for JWT encoding and authentication

  1. Run the project
node app.js

OR, if you have nodemon installed

npm start

API endpoints

Endpoint Purpose Features
/ Homepage None
/api/user/register Registration route that saves information of a new user on the database Duplicate user check, password hashing
/api/user/login Login route that returns token on successful login User existance check, Password match check, JWT Creation
/api/private Example private route that can't be accessed without a token "auth-token" header is required, which means user must be logged in to access this route
Examples
Endpoint Purpose Link
/api/examples/pagination/products?limit=100&page=3 Demonstrating Pagination paginationExample.js

Production dependencies

Package Version Purpose
express ^4.18.2 Creating the REST API
jsonwebtoken ^9.0.2 Generating JWT and Authenticating it
mongoose ^6.12.0 Connecting to MongoDB
bcryptjs ^2.4.3 Hashing the password
@hapi/joi ^17.1.1 Schema validation check
joi ^17.10.2 Schema validation check
dotenv ^10.0.0 Loads environment variables
cors ^2.8.5 enable CORS
express-rate-limit ^7.1.0 Rate limiting for Users

Contributions

Contributions are welcomed, to learn more about it, please check Contributing.md.

Current Contributors

express-jwt-boilerplate's People

Contributors

hammedbabatunde avatar jayeshmann avatar shrenik0321 avatar udz-codes avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.