Skip to content

nazmulsujon/express-js-boilerplate

Repository files navigation

Express.js | TypeScript | Mongoose Boilerplate

This repository provides a boilerplate for building scalable and maintainable backend applications using Express.js, TypeScript, and Mongoose. It includes pre-configured tools like ESLint, Prettier, and ts-node-dev for a smooth development experience.

Features

  • TypeScript: Type safety and modern JavaScript features.
  • Express.js: Fast, unopinionated, minimalist web framework.
  • Mongoose: Elegant MongoDB object modeling for Node.js.
  • ESLint and Prettier: Enforces coding standards and format consistency.
  • Environment Configuration: Manage sensitive data with dotenv.
  • Folder Structure: Well-organized for scalability and readability.

Project Structure

src/
├── controllers/   # Handles request logic
├── interfaces/    # TypeScript interfaces and types
├── models/        # Mongoose schemas and models
├── routes/        # API routes
├── services/      # Business logic
├── utils/         # Utility functions

Prerequisites

Ensure you have the following installed:

  • Node.js (version 16 or higher)
  • Yarn or npm
  • MongoDB

Getting Started

Clone the Repository

git clone https://github.com/nazmulsujon/express-js-boilerplate.git
cd express-js-boilerplate

Install Dependencies

Using Yarn:

yarn install

Or using npm:

npm install 

Environment Variables

Create a .env file in the root directory and add the following variables:

PORT=5000
MONGO_URI=mongodb://localhost:27017/your_database_name
Run the development server
Using Yarn:
yarn dev

Or using npm:
npm run dev

The server will start on http://localhost:5000.

Build for production
Using Yarn:
yarn build

Or using npm:
npm run build

Available Scripts

yarn dev / npm run dev: Start the development server with hot-reloading.
yarn lint / npm run lint: Lint the code using ESLint.
yarn build / npm run build: Compile TypeScript to JavaScript.

API Endpoints

Example Routes
GET /api/example: Fetch example data.
POST /api/example: Create new data.
Test Routes
GET /api/test: Test the API.
POST /api/test: Test POST functionality.

Tools and Libraries

TypeScript Express.js Mongoose ESLint Prettier ts-node-dev dotenv

Contribution Feel free to submit issues or pull requests. Any contributions are highly appreciated!

Releases

No releases published

Packages

No packages published