Create a NestJS Project Step by Step

1. Install Node.js

Install the latest active Node.js LTS version. Current NestJS documentation requires Node.js 20.19 or later to run Nest applications, and newer versions may be required by the latest CLI generators.

Check that Node.js and npm are installed:

node --version
npm --version

2. Install the NestJS CLI

Open a terminal and run:

npm install -g @nestjs/cli

Verify the installation:

nest --version

3. Create a new project

Run:

nest new my-nest-app

Replace my-nest-app with your preferred project name.

The CLI will ask you to choose:

  • A package manager, such as npm or yarn
  • A module system: ESM or CommonJS
  • Whether to enable NestJS Observe

For a beginner, the default choices are usually suitable. The command creates the project folder, installs dependencies, and generates the standard NestJS files.

4. Enter the project directory

cd my-nest-app

5. Start the development server

npm run start:dev

This starts the server in watch mode, so it automatically restarts when you edit files.

Open this URL in your browser:

http://localhost:3000

You should see:

Hello World!

6. Understand the project structure

Your project will look similar to this:

my-nest-app/
├── src/
│   ├── app.controller.ts
│   ├── app.controller.spec.ts
│   ├── app.module.ts
│   ├── app.service.ts
│   └── main.ts
├── test/
├── package.json
├── tsconfig.json
└── nest-cli.json

The important files are:

  • main.ts — starts the NestJS application
  • app.module.ts — root module
  • app.controller.ts — handles HTTP routes
  • app.service.ts — contains application logic
  • package.json — dependencies and npm scripts

7. Generate a feature

For example, generate a users feature:

nest generate module users
nest generate controller users
nest generate service users

Short versions:

nest g module users
nest g controller users
nest g service users

This creates files such as:

src/users/
├── users.controller.ts
├── users.module.ts
└── users.service.ts

8. Add a test route

Open src/users/users.controller.ts and use:

import { Controller, Get } from '@nestjs/common';

@Controller('users')
export class UsersController {
  @Get()
  findAll() {
    return ['Alice', 'Bob'];
  }
}

Make sure UsersController is registered in users.module.ts:

import { Module } from '@nestjs/common';
import { UsersController } from './users.controller';
import { UsersService } from './users.service';

@Module({
  controllers: [UsersController],
  providers: [UsersService],
})
export class UsersModule {}

Then make sure UsersModule is imported into src/app.module.ts:

import { Module } from '@nestjs/common';
import { UsersModule } from './users/users.module';

@Module({
  imports: [UsersModule],
})
export class AppModule {}

Visit:

http://localhost:3000/users

You should receive:

["Alice", "Bob"]

9. Useful commands

# Start normally
npm run start

# Start with automatic reload
npm run start:dev

# Build the project
npm run build

# Run tests
npm run test

# Run end-to-end tests
npm run test:e2e

# Check and format code
npm run lint
npm run format

By davs