Skip to content

sankalpmukim/nest-prisma-rest-api-boilerplate

 
 

Repository files navigation

7Code Logo

Description

Nest + Prisma + TypeScript starter repository.

Production-ready REST API:

  • Error Handling (Exception Filters)
  • Logging System
  • DB Seeds/Migrations
  • Built-in AuthModule, using JWT. Route Guards
  • Model Events Listener (onCreated, …)
  • Deployable. CI/CD pipeline using Github Actions.
  • Advanced ESLint/TSLint config. (e.g: auto-fix will remove unused imports)
  • Shared services/constants/helpers
  • Middlewares/Interceptors implementation example.

TO-DO

Installation

$ npm install

Running the app

# development
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod

Test

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov

Prisma (ORM)

# IDE for your database
$ npx prisma studio 

# run migrations (apply schema changes)
$ npx prisma migrate dev

# run migrations on CI/CD
$ npx prisma migrate deploy

# apply db schema changes to the prisma client
$ npx prisma generate

Auth

This implementation uses httpOnly (server-side) cookie-based authentication. Read more

That means that the JWT Token is never stored on the client. Usually it was stored in localStorage / sesionStorage / cookies (browser), but this is not secure.

Storing the token on a server side cookie is more secure, but it requires a small adjustment on frontend HTTP requests in order to work.

Frontend adjustments

  • If you're using axios then you need to set: withCredentials: true. Read more
  • If you're using fetch then you need to set: credentials: 'include'. Read more

Code Style

Sync your IDE with project eslintrc.js.

Check Run ESLint --fix on save

Stay in touch

License

MIT licensed.

About

Nest + Prisma + TypeScript | REST API Starter repository

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 95.4%
  • JavaScript 3.2%
  • Shell 1.4%