Install Nestjs CLI to start and generate CRUD resources
npm i -g @nestjs/cli
Install the dependencies for the Nest application:
npm install
copy vars of .env.example to .env
Prisma Migrate is used to manage the schema and migration of the database. Prisma datasource requires an environment variable DATABASE_URL
for the connection to the PostgreSQL database. Prisma reads the DATABASE_URL
from the root .env file.
Use Prisma Migrate in your development environment to
- Creates
migration.sql
file - Updates Database Schema
- Generates Prisma Client
npx prisma migrate dev
# or
npm run migrate:dev
If you like to customize your migration.sql
file run the following command. After making your customizations run npx prisma migrate dev
to apply it.
npx prisma migrate dev --create-only
# or
npm run migrate:dev:create
If you are happy with your database changes you want to deploy those changes to your production database. Use prisma migrate deploy
to apply all pending migrations, can also be used in CI/CD pipelines as it works without prompts.
npx prisma migrate deploy
# or
npm run migrate:deploy
Prisma Client JS is a type-safe database client auto-generated based on the data model.
Generate Prisma Client JS by running
Note: Every time you update schema.prisma re-generate Prisma Client JS
npx prisma generate
# or
npm run prisma:generate
Run Nest Server in Development mode:
npm run start
# watch mode
npm run start:dev
Run Nest Server in Production mode:
npm run start:prod
GraphQL Playground for the NestJS Server is available here: http://localhost:3000/graphql
Open up the example GraphQL queries and copy them to the GraphQL Playground. Some queries and mutations are secured by an auth guard. You have to acquire a JWT token from signup
or login
. Add the accessToken
as followed to HTTP HEADERS in the playground and replace YOURTOKEN
here:
{
"Authorization": "Bearer YOURTOKEN"
}
RESTful API documentation available with Swagger.
Update the Prisma schema prisma/schema.prisma
and after that run the following two commands:
npx prisma generate
# or in watch mode
npx prisma generate --watch
# or
npm run prisma:generate
npm run prisma:generate:watch