1. Foundations
Core concepts you need before writing code.
Why foundations matter
Before touching any code it helps to understand the tools NestJS relies on. This page explains the high-level concepts; the step-by-step pages that follow will put them into practice.
npm in a nutshell
- npm stands for Node Package Manager. It ships with Node.js and lets you install third-party libraries.
- The command
npm install <package>downloads the package into the localnode_modules/folder and records it inpackage.json. - Use
npxto run CLI tools temporarily without installing them globally (e.g.,npx @nestjs/cli new task-api).
Tip: You can view every available npm script by running
npm runwith no arguments.
What is package.json?
Every Node project includes a package.json file that describes the app:
{
"name": "task-api",
"version": "0.0.1",
"scripts": {
"start": "nest start",
"start:dev": "nest start --watch"
},
"dependencies": {
"@nestjs/common": "^10.0.0"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0"
}
}scriptsdefine shortcuts likenpm run start:dev.dependencieslist packages needed at runtime.devDependencieslist packages used only during development (testing, build tooling, etc.).
Dependency types
- Use
npm install <package>for runtime dependencies. - Use
npm install -D <package>(or--save-dev) for development-only tools such as linters or testing libraries. - Removing a package requires two steps:
npm uninstall <package>and deleting any custom code that referenced it.
With these concepts in mind, continue to Prerequisites to set up your machine, then follow Project Setup and Project Tour to see how these ideas appear in a real NestJS project.