A Boilerplate for Express Apps with Prisma
This repo includes some features that are important to me:
- using Typescript
- Hot Reload in Development
- Using Docker for running Database
- Using a ORM/ODM for the Database(in this case Prisma)
- Linting
- Formatter
- Validator
- Testing(Both unit and integration)
- Using Conventional Commit(Forced by commitlint package)
- Having Git Hooks(using Husky => pre/post)
- Documentation(use TS Docs, JS Docs and typedoc package to turn them to html pages)
- Having a proper pipeline(install, build, lint, format, test)
- Monitoring using Prometheus and Grafana
Nodejs and NPM: You can install the latest version here
docker: Install docker engine from here.
First install dependencies:
npm install
And then start the project:
The App is running inside a docker container, it supports hot reload.
docker compose up
Now the service is up and is listening on: http://127.0.0.1:3001
Be aware that you need DATABASE_URL
as a env variable on your system for running the project or tests. You can create a .env
file in Prisma folder to do that.
We are using Jest as both test library and test runner. For running ts test files we are using SWC which is a lot faster than TS-NODE. This issue of detecting open handles on tests is open on jest: prisma/prisma#18146
Available scripts in package.json
file:
npm run test
npm run test:watch
npm run test:ci
Be aware that you need DATABASE_URL
as a env variable on your system for running the project or tests. You can create a .env
file in Prisma folder to do that.
For using your own coverage badge you need to do 3 things:
- Register in CodeCov
- Copy the Secret
CODECOV_TOKEN
value and add it to your project secrets. - Copy the Badge address from CodeCov dashboard to README file.
For Linting and Formatting we are using Biome
npm run lint
npm run format
Promettheus is available on port: 9090
and Grafana is available on port: 3000
. By default Prometheus is added as a datasource to Grafana. For creating a new dashboard, login to Grafana and add a new dashboard and use Prometheus as the datasource.
You can find the default one here: ./grafana/node_dashboard.json
It is forced to commit Conventional Commit to this repository. For commiting in this style you can use this VSCode Extension or use this CLI Tool that I implemented.
Add your documents as TS comments in your project and then run this command for generating .MD
files in docs
folder:
npm run docs
We are using Zod for validation of requests. Check out src/user.service.ts
to see the example.
Pipeline has these steps:
- Installing Dependencies
- Lint
- Run Test Containers
- Wait
- Test