/nestjs-example

More integration example: https://github.com/grimmer0125/full-stack-example

Primary LanguageTypeScript

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

NPM Version Package License NPM Downloads Travis Linux Coverage Gitter Backers on Open Collective Sponsors on Open Collective

Description

A Nest TypeScript example repository. Test restful with JWT authorization and graphql (with authorization and subscription) on http://localhost:3001

Installation

$ yarn install

Running the app

# development
$ yarn run start

# watch mode
$ yarn start:dev

# production mode
$ yarn start:prod

Or use VSCode+F5 to launch debugging mode.

Try restful and graphql

In terminal

Login to get token:

$ curl -X POST http://localhost:3001/auth/login -d '{"username": "john", "password": "changeme"}' -H "Content-Type: application/json"

Try using auth token to get profile:

$ curl http://localhost:3001/profile -H "Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2Vybm..."

In playground

Open http://localhost:3001/graphql, test following graphql commands.

query whoami {
  whoAmI {
    id
    firstName
    lastName
  }
}

subscription commentAdded{
  commentAdded {
    id
    author
  }
}

mutation addComment{
  addComment(comment:"test", postId:7) {
    id
    author
  }
}

# paste the token from terminal
header:
{
  "authorization": "Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImpvaG4iLCJzdWIiOjEsImlhdCI6MTU5NDgwNTc3MCwiZXhwIjoxNTk5OTg5NzcwfQ.yzjP-Y36P3__ED_RpfwkVIRdypGAGoXz9iDdta-KFB4"
}

Unit Tests and & End To End Tests

# unit tests
$ npm run test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov