A ready-to-use boilerplate for REST API Development with Node.js, Express, TypeScript and PostgreSQL.
- Dependency management: with npm
- Linting: with ESLint and Prettier
- Git hooks: with husky and lint-staged
- Environment variables: using dotenv
- CORS: Cross-Origin Resource-Sharing enabled using cors
- Security: set security HTTP headers using helmet
- Logging: using morgan and chalk
- SQL database: PostgreSQL with Prisma
- Validation: request data validation using Zod
- Testing: unit and integration tests using Jest and SuperTest
- Error handling: centralized error handling mechanism
- API documentation: with swagger-jsdoc and swagger-ui-express
- Sanitizing: Sanitize request data against XSS and query injection
- Compression: gzip compression with compression
- CI / CD: continuous integration and deployment with Github Action
- Docker support
- Code coverage: using coveralls
- Editor config: consistent editor configuration using EditorConfig
- Authentication and authorization: using passport
This boilerplate uses the following libraries and tools:
- TypeScript
- ESLint for linting.
- Prettier
- Husky
- CommitLint
- nodemon
- jest
- supertest
- Prettier with EsLint
- Setup test env.
- Sentry or Datadog for error logs
- Prisma & Database setup
- DI
- Zod
- Docker
- Github actions - CI / CD
.
├── .husky # Github hooks for husky
├── build # Built, ready-to-serve app.
├── config # Root folder for configurations.
│ └── index.ts # App configurations.
├── node_modules # Node Packages.
├── source # Source code.
│ ├── bootstrap # Root folder for bootstrapping the app.
│ │ ├── index.ts # Sets up basic middleware
│ │ └── db.config.ts # Sets up DB
│ ├── route # Folder for app routes.
│ │ └── index.ts # Root level routes
│ ├── interface # Folder for interfaces.
│ │ └── user.interface.ts # User interface
│ ├── service # Folder for services.
│ │ ├── index.ts # Common place to export other services
│ │ └── auth.service.ts # Auth service layer
│ └── middleware # Folder to hold all middleware functions
│ └── logging.ts # Middleware for logging into console.
├── .dockerignore # Tells docker which files to ignore.
├── .gitignore # Tells git which files to ignore.
├── .prettierignore # Tells prettier which files to ignore
├── .eslintrc.js # Eslint configuration
├── .prettierrc # Prettier configuration
├── commitlint.config.js # commitlint configuration for husky
├── Dockerfile # Dockerfile.
├── LICENSE # License file
├── package.json # Package configuration.
├── package-lock.json # Package lock
├── README.md # This file
└── tsconfig.json # TypeScript transpiler configuration.
You can clone from this repository and use the main branch.
$ git clone https://github.com/beevk/ts-express-postgres.git projectName
$ cd projectName
$ npm i
All commands default to the development environment. You can set NODE_ENV
to production
or use the shortcuts below.
# Running
$ npm run dev # This starts the app in development mode
# Starting it with the production build (todo)
$ NODE_ENV=production npm run start # or
# Building (todo)
$ npm run build # This builds the app in development mode
# Commands below builds the production build (todo)
$ NODE_ENV=production npm run build # or
$ npm run build:prod
# Testing (todo)
$ npm run test
# Testing with watch mode(todo)
$ npm run test:watch
# Too check test coverage (todo)
$ npm run coverage
This boilerplate is released under the MIT license.