3 min read

NestJS | Generator

Nest.JS —is a progressive Node.js framework for building efficient, reliable and scalable server-side applications.

Nest.JS —is a progressive Node.js framework for building efficient, reliable and scalable server-side applications.

Yeoman — is an open source client-side scaffolding tool for web applications. Yeoman runs as a command-line interface written for Node.js and combines several functions into one place, such as generating a starter template, managing dependencies, running unit tests, providing a local development server, and optimizing production code for deployment.


So, in this tutorial I’ll try to help you on the first steps on how to create a NestJS 8 application.

Installation

First of all, we need an application template that we want to generate. For the test, you can take my ready-made template. Next, you need to install Yeoman with the command:npm install -g yo

then install Nest.js app generator:npm install -g generator-nest-js-boilerplate

and generate your new project:yo nest-js-boilerplate

Steps:

  1. Choose the package manager for your app:

2. Do you want install stable packages`s versions? (recommend choose ‘Yes’)

3. Application name, port, host:

4. Auth (JWT, auth0, sessions), example with JWT:

5. You can try JSON:API specification for building apis in json (lets skip for now):

6. Choose db for your api (Sql — TypeORM, Mongo — Mongoose):

7. Do you want to have a possibility to send emails?(skip for now):

8. Do you want to use web sockets?(skip for now):

9. Do you want to have a possibility to deploy on Heroku?

Example App Skeleton (for Mongo + JWT + WS)

Running the API

Development

To start the application in development mode, run:npm run start:dev

Start the application in production env:

Install ts pm2 and typescript compiler:npm install -g pm2
pm2 install typescript

example start with scale on 2 core:pm2 start ./dist/main.js -i 2 --no-daemon

Server listening on http://localhost:3000/, in development mode The developer mode will watch your changes then will transpile the TypeScript code and re-run the node application automatically.

Documentation

WebSocket API

TypeDoc

TypeDoc documentation will be available after entering the command:npm run docs

REST API

Swagger

Swagger documentation will be available on route:http://localhost:3000/api

Please note: All users not verified by default. Please set "verified": true, for sign-in request.

This boilerplate helps to focus on business requirements implementation instead of investing time in a project setup. Feel free to improve it.

If you have any questions or feedback about this article, feel free to leave a comment.
Thanks for reading.

GitHub link.

NPM link.

Our team.