An opinionated project scaffold for a REST API with express / typescript.
- [server] Express.js
- [language] Typescript
- [nodemon] Hot reloading development environment
- [dotenv] .env parsing into configuration before startup
- [custom] Global configuration files parsed before startup
- [prisma] Database ORM & migrations
- [custom] Sane project structure with middleware, controllers, routes, configuration, exceptions, services, etc.
- [japa] Unit testing with japa, supertest, and jest expectations.
This project structure is inspired by an older version of Adonis.js. It seemed sane, scalable, and simple.
app/
- All of the application logic.exceptions/
- Exceptions & Exception handlershttp/
controllers/
- Route controllers / logic.middleware/
- All HTTP middleware.
routes/
- Collection of routers/routes.services/
- Business logic / where the 'how' is implemented.
bin/
- Japa unit test runnerconfig/
- Dedicated, importable configuration files.prisma/
- Anything to do with prisma database schemas / migrations.tests/
- Unit testsapp.ts
- Entry point to the applicationserver.ts
- Starts the server / event loop..env
- Environmental variables loaded by DotEnv.
Here are some key resource links that I found useful
- Express.js
- Express Routing Guide
- Express Writing Middleware Guide
- Express Using Middleware Guide
- Express Error Handling
- Express Best Practices: Security
- Express Best Practices: Performance & Reliability