This project contains boilerplate for creating APIs using Nest, a progressive Node.js framework for building efficient and scalable server-side applications.
It is mostly built to be used as a starting point and implements common operations such as sign up, JWT authentication, mail validation, model validation and database access.
-
PostgreSQL with Prisma
-
JWT Authentication
-
Mail Verification
-
Mail Change
-
Password Reset
-
Request Validation
-
Customizable Mail Templates
-
Swagger API Documentation
-
Security Techniques
-
Logger
- Make sure that you have Node.js(>= 10.13.0, except for v13) installed.
- Clone this repository by running
git clone https://github.com/zerothebahdman/nestjs-prisma-starter.git
or directly create your own GitHub repository using this template. - Move to the appropriate directory:
cd <YOUR_PROJECT_NAME>
. - Run
yarn
to install dependencies.
Prisma Configurations
This template uses Postgres by default. If you want to use another database, follow instructions in the official Nest recipe on Prisma.
If you wish to use another database you will also have to edit the connection string on .env
file accordingly.
Your database url in the `.env` file should as follows
DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
mydb : The name of the databse you created on your machine
johndoe : The username of the database
randompassword : The password of the database
A delivery provider is required for sending mails with Nodemailer. I mostly use MailTrap to send mails, however, Nodemailer can work with any service with SMTP transport.
To get a MailTrap API key:
- Create a free account from https://mailtrap.io/
- Confirm your account via the activation email and login.
- Create an API Key with mail sending capability.
Enter your API key and sender credentials to .env
file. Sender credentials are the sender name and sender mail that will be seen by your users.
MAIL_FROM=
MAIL_HOST=
MAIL_PORT=
MAIL_USER=
MAIL_PASSWORD=
Please refer to the official Prisma Migrate Guide to get more info about Prisma migrations.
# generate migration for local environment
$ yarn migrate:dev:create
# run migrations in local environment
$ yarn migrate:dev
# deploy migration to prod environment
$ yarn migrate:deploy:prod
# development mode
$ yarn start:dev
# production
$ yarn build
$ yarn start:prod
# unit tests
$ yarn test
# e2e tests
$ yarn test:e2e
# test coverage
$ yarn test:cov
Nest is an MIT-licensed open source project. If you'd like to join support Nest, please read more here.
Licenced under MIT License. Nest is also MIT licensed.