Environment Setup & the Nest CLI
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.
Installing the Nest CLI
Install it globally so the nest command is available anywhere:
Creating a new project
Scaffold a fully working application with a single command:
Your API is now running on http://localhost:3000 with hot reload — every save restarts the server automatically.
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:
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 indist/.start:prod— run the compiled app.test/test:e2e— run unit and end-to-end tests with Jest.lint— run ESLint across the project.
.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.