create-express-mongodb-ts-starter
v1.0.11
Published
Scaffold a new Express + MongoDB + TypeScript project
Downloads
67
Maintainers
Readme
create-express-mongodb-ts-starter
A CLI tool to scaffold a ready-to-use Express + MongoDB + TypeScript application in seconds.
Quick Start
# npm
npx create-express-mongodb-ts-starter my-app
# yarn
yarn create express-mongodb-ts-starter my-app
# pnpm
pnpm create express-mongodb-ts-starter my-app
# bun
bun create express-mongodb-ts-starter my-appThen install dependencies and start the dev server:
cd my-app
npm install # or: yarn install / pnpm install / bun install
npm run dev # or: yarn dev / pnpm dev / bun devWhat You Get
A fully-structured Express app with:
Tech Stack
- Express 5.x - Web framework
- MongoDB + Mongoose 8.x - Database
- TypeScript - Type safety
- Zod - Schema validation
- Swagger/OpenAPI - API documentation
- Pino - Fast logging
- ESLint + Prettier - Code quality
Project Structure
my-app/
├── src/
│ ├── config/ # env, database, middlewares
│ │ ├── database.ts # MongoDB connection
│ │ ├── env.ts # Environment variables
│ │ └── middlewares/ # cors, security, rateLimit
│ ├── controllers/ # Route handlers
│ ├── core/
│ │ ├── errors/ # AppError, errorCodes
│ │ ├── responses/ # ApiResponse, SuccessResponse
│ │ └── validation/ # Zod schemas
│ ├── middlewares/ # Request middleware
│ ├── routes/ # Express routes
│ ├── services/ # Business logic
│ ├── types/ # TypeScript types
│ ├── utils/ # Logger, graceful shutdown
│ ├── app.ts # Express app factory
│ └── index.ts # Entry point
├── package.json
├── tsconfig.json
├── env.example
└── eslint.config.jsFeatures Built-in
- Security: Helmet, CORS, Rate limiting, Input sanitization
- Validation: Request body validation with Zod
- Error Handling: Custom errors, error codes, proper HTTP responses
- Logging: Request/response logging with Pino
- API Docs: Swagger UI at
/api-docs - Health Check: Route at
/health - Graceful Shutdown: Clean process termination
Commands
npm run dev # or: yarn dev / pnpm dev / bun dev
npm run build # or: yarn build / pnpm build / bun build
npm start # or: yarn start / pnpm start / bun start
npm run lint # or: yarn lint / pnpm lint / bun lintEnvironment Variables
Copy env.example to .env:
PORT=5001
NODE_ENV=development
MONGO_URI=mongodb://localhost:27017/express-app
ALLOWED_ORIGINS=http://localhost:3000,http://localhost:3001
RATE_LIMIT_WINDOW_MS=900000
RATE_LIMIT_MAX_REQUESTS=400License
MIT
