Skip to content

KarthikrajS/node-boilerplate

Repository files navigation

Backend Boilerplate

A scalable and secure backend boilerplate for building Node.js/Express applications. This setup includes authentication, MongoDB integration, and middleware for a production-ready backend API.

Features

Express.js Framework: Lightweight and extensible. MongoDB Integration: Pre-configured with Mongoose for schema-based data modeling. JWT Authentication: Includes ready-to-use register and login endpoints with JWT-based authentication. Validation Middleware: Input validation using express-validator. Error Handling: Centralized error-handling middleware for clean and consistent responses. Secure Routes: Middleware (protect) to guard protected routes.

Getting Started

Clone the Repository

npx degit KarthikrajS/node-boilerplate my-backend
cd my-backend

Install Dependencies

npm install

Set Up Environment Variables

Create a .env file in the project root with the following variables:

makefile

MONGO_URI=mongodb://localhost:27017/my-database
JWT_SECRET=your_jwt_secret
PORT=5000

Run the Server

Start the development server:

npm start

The server will run at http://localhost:5000 by default.

Folder Structure

backend/
├── controllers/        # Logic for handling requests
├── middleware/         # Custom middleware like authentication
├── models/             # MongoDB schemas and models
├── routes/             # API route definitions
├── utils/              # Utility functions (e.g., database connection)
├── .env                # Environment variables
└── index.js           # Entry point of the application

Available Endpoints

Authentication

Method  |   Endpoint  |     Description	                |   Auth Required
POST    |   /register |	    Register a new user         |   No
POST    |   /login    |     Login and retrieve a token	|   No

Protected Example

Method  |   Endpoint  |     Description         |	Auth Required
GET	    |   /protected|     Example of a route	|   Yes

Features to Customize

Add additional models for your application in models/. Extend the API routes in routes/ with new features. Improve error handling and logging based on your project needs.

Contributing

Feel free to fork this repository and make your contributions. Open a pull request to submit changes.

License

This project is licensed under the MIT License.

About

Node MSA boilerplate with user-service

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published