NestJS — Enterprise Node.js

Environment Setup & the Nest CLI

13 min Lesson 2 of 48

Environment Setup & the Nest CLI

Before writing NestJS code you need Node.js and the Nest CLI — the official command-line tool that scaffolds projects, generates building blocks, and runs your app in development. The CLI is the fastest way to stay consistent with NestJS conventions.

Prerequisites

  • Node.js (LTS version, 18 or newer recommended). Check with node -v.
  • A package manager — npm (bundled with Node), or pnpm / yarn.
  • TypeScript knowledge — decorators and types are used everywhere.
Why the LTS version? NestJS targets actively supported Node releases. Older versions may lack features the framework relies on, and very new "Current" releases can be unstable for production.

Installing the Nest CLI

Install it globally so the nest command is available anywhere:

npm install -g @nestjs/cli # verify it installed nest --version

Creating a new project

Scaffold a fully working application with a single command:

nest new my-app # the CLI asks which package manager to use, then installs everything cd my-app npm run start:dev

Your API is now running on http://localhost:3000 with hot reload — every save restarts the server automatically.

start:dev uses watch mode for development. For production you compile once with npm run build and run npm run start:prod, which executes the compiled JavaScript from the dist/ folder.

The most useful CLI commands

The generate command (aliased g) scaffolds building blocks with the correct files, naming, and module wiring:

# generate a full CRUD resource (module + controller + service + DTOs) nest g resource users # or generate pieces individually nest g module users nest g controller users nest g service users

Generating a controller, for example, creates the file, its test spec, and registers it in the nearest module — no manual wiring.

Understanding the npm scripts

  • start:dev — run in watch mode (development).
  • build — compile TypeScript to JavaScript in dist/.
  • start:prod — run the compiled app.
  • test / test:e2e — run unit and end-to-end tests with Jest.
  • lint — run ESLint across the project.
Don't commit the dist/ or node_modules/ folders. The generated .gitignore already excludes them — dist/ is a build artefact and node_modules/ is restored with npm install.

Summary

Install Node.js LTS and the Nest CLI, scaffold a project with nest new, and use nest g to generate consistent building blocks. The start:dev script gives you hot-reload development. Next we will open the generated project and understand how it boots.