A professional, well-structured TypeScript Node.js API built with Express and MongoDB (Mongoose). This project is designed as a clean starter for building production-grade REST APIs with TypeScript, strong typing, validation, centralized error handling, and sensible defaults for pagination, filtering and searching.
Key highlights
- TypeScript-first codebase with strict compiler settings
- Express for HTTP routing and middleware
Table of contents
- Project status
- Tech stack
- Quick start
Project status
- Version: 2.0.0
- Node.js + TypeScript
- Express
- Clone the repository and install dependencies
git clone https://github.com/md-abu-kayser/typescript-express-mongoose-starter.git
- Create environment file(s)
This project loads environment variables using dotenv. Copy or create an .env file at the repository root. Example values:
- Run in development (auto-reload)
npm run start:dev
## Environment variables
- PORT (required) - HTTP port the server will listen on
- DATABASE_URL (required) - MongoDB connection string
## Available npm scripts
- `npm run start:dev` - Start the app in development using `ts-node-dev` (auto-reload)
- `npm run start:prod` - Run the built production bundle (`node dist/server.js`)
## How the app starts
- Entry point for development: `src/server.ts` - connects to MongoDB then starts the Express app.
- Main Express application: `src/app.ts` - registers middleware, health check and routes.
GET /health
Base path: /api/v1/students
- Create a student
- POST /
- Body shape: { student: { ... } }
- Get students (list)
- GET /
- Query params supported:
- Get single student
- GET /:studentId
- Returns 200 and the student document, or 404 if not found.
- Update student
- PATCH /:studentId
- Body shape: { student: { ...fieldsToUpdate } }
- Delete student (soft delete)
- DELETE /:studentId
- Soft deletes the record by setting
isDeleted: trueand returns the updated document.
Key fields (see src/app/modules/student/student.interface.ts and student.model.ts):
Request validation uses Zod schemas (src/app/modules/student/student.validation.ts) and the validateRequest middleware (src/app/middlewares/validateRequest.ts).
AppError(src/app/utils/AppError.ts) is used to create operational errors with a status code.globalErrorHandler(src/app/middlewares/globalErrorHandler.ts) serializes errors and sends a consistent JSON error envelope.
src/server.ts- app bootstrap, DB connection and process-level error handlingsrc/app.ts- Express initialization, global middleware, and route mounting
Unit and integration tests can be written using Jest (configured in package.json). Example:
Contributions are welcome. A recommended workflow:
- Ensure
NODE_ENV=productionand supply a secureDATABASE_URLwhen deploying. - Build (
npm run build) before starting the production process.
- This project is licensed under the terms of the MIT License.
- You may replace or update the license as needed for client or proprietary projects.
Maintainer: md-abu-kayser
Name: Md Abu Kayser - Full-Stack Engineer
- GitHub: github.com/abu.kayser-official
- Email: abu.kayser.official@gmail.com
- Project: typescript-express-mongoose-starter
If you’d like this README tailored for a specific purpose - such as hiring managers, open-source contributors, or client deliverables - feel free to request a custom tone or format.
Thank You For Reviewing This Project!