Skip to content

ruhit07/node-express-boilerplate

Repository files navigation

A boilerplate for building RESTful APIs using Node.js, Express.js and MongoDB

Manual Installation

If you would still prefer to do the installation manually, follow these steps:

Clone the repo:

git clone https://github.com/ruhit07/node-express-boilerplate.git
cd node-express-boilerplate

Install the dependencies:

npm install

Set the environment variables:

cp .env.example .env

# open .env and modify the environment variables (if needed)

Features

  • NoSQL database: MongoDB sql query builder using mongoose
  • Authentication: using jsonwebtoken
  • Validation: request data validation using Joi
  • Logging: using morgan
  • Error handling: centralized error handling mechanism
  • Dependency management: with Npm
  • Environment variables: using dotenv
  • Security: set security HTTP headers using helmet, HTTP parameter pollution attacks using hpp and sanitizes user-supplied data using express-mongo-sanitize
  • CORS: cross-origin resource-sharing enabled using cors

Commands

Running locally:

npm run dev

Environment Variables

The environment variables can be found and modified in the .env file. They come with these default values:

NODE_ENV = development
PORT = 5000

MONGO_URI = mongodb://localhost:27017/test

JWT_SECRET=gsdhgfhdgshgh4g54b5s4fg5
JWT_EXPIRE=1d
JWT_COOKIE_EXPIRE=1

Project Structure

|--config\               # Environment variables and configuration related things
|--controllers\          # Controller layer
|--enums\                # Common enum values
|--middlewares\          # Custom express middlewares
|--model\                # Modules
|--routes\               # Routes
|--utils\                # Utility classes and functions
|--validations\          # Request data validation schemas
|--server.js             # App entry point

API Endpoints

List of available routes:

Auth routes:
POST /api/v1/auth/register - register
POST /api/v1/auth/login - login
DELETE /api/v1/auth/logout - logout
GET /api/v1/auth/me - retriving his profile
DELETE /api/v1/auth/me - delete currect user
PUT /api/v1/auth/updatedetails - update his details
PUT /api/v1/auth/updatepassword - update his password

User routes:
GET /api/v1/users - get all users
GET /api/v1/users/:id - get user
POST /api/v1/users - create a user
PUT /api/v1/users/:id - update user
DELETE /api/v1/users/:id - delete user

About

A boilerplate for building RESTful APIs using Node.js, Express.js and MongoDB

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published