Create a .env file and add these lines:
PORT=8000
MONGODB_URL=mongodb://localhost:27017/temp
Note: You'll have to install MongoDB locally on your machine first. Or you can get a URL from MongoDB Atlas and use that instead.
Install dependencies and run the development server:
npm i
npm run devThe server will then start listening to the requests on this URL:
REST APIExample (with MongoDB)- Well-organized
Folder Structure- Separation of
Models,Controllers,Services, andRoutes
- Separation of
- Added
Error Handlermiddleware - Throw custom
Errors- Respond with custom error messages by just throwing errors!
- No need to use
res.status(4xx).json(error)
- Added
Winston Logger- Configured to write to STDOUT and log files
- Pre-configured with
TypeScript&Prettier
- Add a
Testing Library - Validation/sanitization of request params, query, and body.
- Add
Authentication - Use of
DTO(Data Transfer Object) - Validate
envvariables
- Run TypeScript on prod using
ts-node?--transpile-onlyto reduce memory footprint
- Build locally and then push the complied js files to GitHub?
- But it will pollute the changed files in the commits
- Use
HuskyorGitHub Actions, or both?