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.
- 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.
src/
├── controllers/ # Handles request logic
├── interfaces/ # TypeScript interfaces and types
├── models/ # Mongoose schemas and models
├── routes/ # API routes
├── services/ # Business logic
├── utils/ # Utility functions
Ensure you have the following installed:
- Node.js (version 16 or higher)
- Yarn or npm
- MongoDB
git clone https://github.com/nazmulsujon/express-js-boilerplate.git
cd express-js-boilerplate
yarn install
npm install
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
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.
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.
TypeScript Express.js Mongoose ESLint Prettier ts-node-dev dotenv
Contribution Feel free to submit issues or pull requests. Any contributions are highly appreciated!