- Production Ready
- TypeScript
- MongoDB setup
- Error & Exception Handler
- Morgan & Winston Logger
- Jest, Supertest Api Testing
- Automatic Swagger Docs Generation
- ZOD Validation
- Api Versioning
- Scalable for large projects
Clone the repo to backend directory:
git clone https://github.com/ankushknr19/ts-express-mongo-starter-code.git backend
Install dependencies
cd backend
npm install
npm run build
- rename .env.example file to .env
- replace the values with your own valid values
npm run test
npm run dev
(or) Perform CRUD operations from rest.example.http file
-
it is used to create errors with proper http status code
-
throwing error in try block:
try { throw new createHttpError.BadRequest() }
- accepts error object as first parameter
- executed whenever a middleware calls next(error)
- in any middleware, in catch block:
catch{ next(error) }
-
5 levels: error, warn, info, http & debug
-
morgan creates http logs
-
instead of doing console.log(), do:
import logger from './utils/winstonLogger' logger.error('error message') logger.warn('warning message')
- first create a variable in .env file
- then import and declare it in config/env.ts file