Quick Commands for NestJS/CLI

A list of available architecture components:

$ nest generate service users
$ nest g s users

A list of available architecture components:

class (alias: cl)
controller (alias: co)
decorator (alias: d)
exception (alias: e)
filter (alias: f)
gateway (alias: ga)
guard (alias: gu)
interceptor (alias: i)
middleware (alias: mi)
module (alias: mo)
pipe (alias: pi)
provider (alias: pr)
service (alias: s)
$ npm i -g @nestjs/cli           # installs nestjs
$ npm install -g typescript      # if gives such error, Error: Cannot find module 'typescript'
$ nest new project               # creates new nestjs project

$ npm run start
$ nest g controller cats # creates controller


$ npm i -g @nestjs/cli
$ nest new project

src # The entry file of the application. It uses NestFactory to create the Nest application instance.     # Defines AppModule, the root module of the application.
   ........main.ts           # Basic controller sample with a single route.

The main.ts includes an async function, which will bootstrap our application:


import { NestFactory } from '@nestjs/core';
import { ApplicationModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.create(ApplicationModule);
  await app.listen(3000);

To create a Nest application instance, we are using the NestFactory. NestFactory is one of the most fundamental classes, it exposes a few static methods that allows creating application instance. The create() method returns an object, which fulfills the INestApplication interface, and provides a set of usable methods which are well described in the next chapters.

Running application

Once the installation process is complete, you can run the following command to start the HTTP server

$ npm run start

This command starts the HTTP server on the port defined inside the src/main.ts file. While the application is running, open your browser and navigate to http://localhost:3000/. You should see the Hello world! message.