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)
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:
npm run start:dev
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
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.
Got to .husky/commit-msg
and comment the line that checks commit message. You can also remove these two packagees if you do not want to have a standard on commit messages: "@commitlint/cli": "^17.4.4"
, "@commitlint/config-conventional": "^17.4.4"
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