The TypeScript Express Mongoose Starter is a powerful boilerplate for TypeScript web applications. It combines Express.js, TypeScript, and Mongoose to create ro
The TypeScript Express Mongoose Starter is a powerful boilerplate for TypeScript web applications. It combines Express.js, TypeScript, and Mongoose to create ro
TypeScript Express Mongoose Starter
Express RESTful API Boilerplate with TypeScript and Mongoose
The TypeScript Express Mongoose Starter is a comprehensive boilerplate for building robust and scalable web applications using the TypeScript programming language, Express.js framework, and Mongoose ODM for MongoDB. It provides a solid foundation and a set of best practices to kickstart your TypeScript-based Express projects with ease.
/api-docs.To create a new project using this starter template, you can use npx to quickly scaffold the project. If you don't write the project name yourself, the default name typescript-express-mongoose-starter will be used.
$ npx typescript-express-mongoose-starter Alternatively, you can clone the repository and install the dependencies:
$ git clone https://github.com/ahmadjoya/typescript-express-mongoose-starter.git
$ cd typescript-express-mongoose-starter
$ npm installEnvironment variables are loaded from .env..local — so .env.development.local for npm run dev, .env.test.local for npm test, and .env.production.local for npm start. Copy .env.example as your starting point. Every variable is validated on boot, and the app exits with a clear message if one is missing or malformed.
| Variable | Default | Description |
|---|---|---|
PORT |
3000 |
Port the HTTP server listens on |
DB_HOST |
127.0.0.1 |
MongoDB host |
DB_PORT |
27017 |
MongoDB port |
DB_DATABASE |
dev |
MongoDB database name |
DB_URI |
(unset) | Full connection string. Takes precedence over the three variables above — use this for MongoDB Atlas (mongodb+srv://...) |
SECRET_KEY |
secretKey |
JWT signing secret. Change this before deploying to production |
LOG_FORMAT |
dev |
Morgan log format |
LOG_DIR |
logs |
Log directory, relative to the project root (absolute paths are honoured as-is) |
ORIGIN |
* |
CORS allowed origin |
CREDENTIALS |
true |
Whether CORS allows credentials |
$ npm run dev # start in development with hot reload (nodemon + ts-node)
$ npm start # build and start in production
$ npm test # run the Jest test suite
$ npm run lint # lint with ESLint
$ npm run build # compile to dist/ with SWC| Script | What it does |
|---|---|
dev |
Runs the server through nodemon with hot reload |
start |
Builds and runs the compiled server in production mode |
build |
Compiles src/ to dist/ with SWC (fast) |
build:tsc |
Compiles with tsc + tsc-alias (type-checked build) |
typecheck |
Type-checks the whole project without emitting |
test |
Runs the Jest test suite |
test:coverage |
Runs the tests with a coverage report |
lint / lint:fix |
Lints (and auto-fixes) src/ |
format / format:check |
Formats (and checks) src/ with Prettier |
deploy:dev / deploy:prod |
Starts the app under PM2 using ecosystem.config.js |
Once running, the API docs are available at .
The test suite runs entirely against mocked Mongoose models, so no MongoDB instance is required:
$ npm testnpm test sets NODE_ENV=test, which loads .env.test.local. That file ships with the repo, so the suite works on a fresh clone with no extra setup.
…The src/http folder holds .http files you can execute directly from VS Code with the REST Client extension — a quick way to hit the API by hand without Postman.
Bring up the full stack (API + MongoDB + Nginx reverse proxy):
$ docker compose up -dThe API is then reachable on directly, or through Nginx on .
To build the production image on its own:
$ docker build --target production-build-stage -t typescript-express .Thank you to everyone who has starred this project — see the full list on the stargazers page.
Browse everyone building on top of this starter on the forks page.
Contributions, bug reports, and feature requests are always welcome! If you encounter any issues or have ideas to improve the starter template, please feel free to open an issue or submit a pull request on the GitHub repository.
No open issues yet, or sync has not completed.