Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications.

NPM Version Package License NPM Downloads CircleCI Coverage Discord Backers on Open Collective Sponsors on Open Collective Support us


Table of contents

Click here to expand

Features

I create this repo for learning, practicing and understanding how to work NestJS, GraphQL & Prisma together. Project also how to build a clean architecture scalable & testable.

Features of project:

Prerequisites

If you want to develop project only on your local, your need have:

Getting started

Installation

  • Clone project from this repository

  • Create and update .env file for variables environment

    $ cp .env

    Then modify the variables as you want.

    Example of .env files:

    DB_CONNECTOR=postgres
    DB_HOST=localhost
    DB_USER=chickfool
    DB_PASSWORD=123456
    DB_DATABASE=dummy_db
    DB_PORT=5432
    REFRESH_TOKEN_SECRET="mysecret"
    ACCESS_TOKEN_SECRET="mysecret"
    APP_URL=http://localhost:3000
    IMAGE_PATH=/images
    
    
    DATABASE_URL=postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}?schema=public
  • Install dependencies

    $ yarn
    # or npm install
  • Generate prisma schema Make sure you generate prisma schema before run server:

    $ yarn prisma generate

    Check Prisma Client for more details how prisma generate works

  • Run server locally

    $ yarn start:dev
    # or npm run start:dev

Command lines

Other useful commands to work with project:

  • Run production

    $ yarn start:prod
  • Run testing:

    $ yarn test # for running the the Unit $ integration testing
    $ yarn test:e2e  # for running end to end testing
  • Prisma migrate Prisma migrate is an imperative database schema migration tool that enables you to make changes to your database schema.

    Migrate auto your schema:

    $ yarn prisma migrate dev --preview-feature

    Migrate with the name schema:

    $ yarn prisma migrate dev --name initDb --preview-feature

    When we run prisma generate or prisma migrate, prisma/cli will try connect with your database first. So you need to connect successfully with your database through your variable DATABASE_URL given in prisma.schema:

    For example, you have configuration in your prisma.schema like below:

    // prisma.schema
    datasource db {
      provider = "postgresql"
      url      = env("DATABASE_URL")
    }

    So you need to provide this value in .env file:

    DB_HOST=postgres
    DB_USER=postgres
    DB_PASSWORD=postgres
    DB_DATABASE=nest_graphql
    DB_PORT=5432
    DATABASE_URL="postgresql://${DB_USER}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_DATABASE}?schema=public"
    
    

    Check more information at Prisma migrate

  • Seeding database(optional) If you have any errors, so you can try running command below to sync your database:

    $ yarn prisma db push

    Then you can run seeding database:

    $ yarn seed

    When you run seeding database done. You can use Prisma studio for checking your database. If you see Movie table has empty. Don't worry, when you run server, the server will run seeding database automatically by cron.

  • Prisma studio

    A Visual Interface for Your Database Prisma Studio helps developers manage their application data. We're excited to share that it is now part of the stable Prisma release. Try out the online demo or connect it to your existing database.

    So with Prisma studio, you maybe don't need pgAdmin anymore.

    prisma-studio

    Ton run Prisma studio:

    $ yarn prisma:studio
    # or npx prisma studio
    # or yarn prisma studio

    Then check out at http://localhost:5555

Documentation

You need to run the code below to generate the documentation:

$ yarn document
# or npx document
# or yarn document

You can check out the documentation of project at http://localhost:4400

document
queries
mutations

Docker

To start working with Docker, you need have Docker installed locally and also the package manage as npm ro yarn

In the development mode, we have already PostgreSQL in our docker-compose file. You can use the same values environment in your .env like before.

Command line

$ docker-compose build # Build all services in docker-compose.yml file
$ docker-compose up # Run all services in docker-compose.yml
$ docker-compose down # Stop all services

Thanks

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages