Node Boilerplate Typescript
- This repo is boilerplate for typescript and nodejs projects
What is included
- Server with express
- Security Packages
- File uploading
- Sending Emails
- Logging
- By default it is configured to log on console but you can extend it to write to any file as well
- Object(s) Validation using zod
- Error Handling
- Express Req object extend with typescript support
Routing
- The base path for api will be
api. - Any folder you put inside modules folder that container
routes.tsfile will be added to express router stack and that will be route for the api as well. - So suppose if you make folder something like
modules/v1/file/routes.tsthen all the routes defined in thatroutes.tsfile will be registered and will be available atdomain/api/modules/v1/file. - So think like routing as a file based routing.
- You must export router as default export from
routes.tsfile to make this happen.
Error handling
- You can alway use try catch in your controllers to handle errors by your self, but here I have used different approach.
- Just wrap your any controller/middleware that receives express's
req,resobject wrap them inPromiseHandlerfunction and this will handle the rest of the stuff. - Also you can create custom errors in error folder as per your requirement and handle it in
handleApiErroraccording the way you want.
Top comments (0)