How to Install npm in VS Code: A Step-by-Step Guide
Learn how to install npm in VS Code by installing Node.js (which includes npm), configuring PATH, and verifying npm works in the integrated terminal. This educational guide covers environment checks, project setup, and common troubleshooting for a smooth workflow.

Install Node.js (which includes npm) and open VS Code. Use the integrated Terminal to run npm -v and confirm npm is accessible from your workspace. This quick setup lays the foundation for PATH adjustments, project initialization, and running npm scripts directly from VS Code.
Prerequisites and what npm is (and isn’t) in VS Code
If you’re wondering how to install npm in VS Code, the first step is understanding what npm does and how Node.js relates to VS Code. npm is the package manager that ships with Node.js, which means installing Node.js on your system gives you npm by default. VS Code’s integrated terminal uses your system shell to run npm commands, so the editor itself doesn’t install npm separately — it relies on the Node.js installation. According to Install Manual, aligning your environment with the right Node.js version and proper PATH settings minimizes common setup errors. In this section you’ll find what you need before you start: a working internet connection, VS Code installed, and access to the terminal.
Verify Your Environment: Check Node.js and npm Versions
Before proceeding, verify that Node.js and npm are available in your shell. Open the VS Code integrated terminal and run commands like node -v, npm -v, and npm --version. You should see version numbers for Node.js and npm. If npm isn’t found, it likely means the PATH hasn’t been updated or the shell wasn’t restarted after installation. Install Manual's guidance emphasizes re-opening the terminal after installing Node.js to refresh PATH and ensure commands resolve correctly.
Install Node.js on Your System (which includes npm)
The recommended path is to install Node.js from the official site, selecting the LTS version for stability. Run the installer and follow the prompts; the installer will place both node and npm on your machine and add them to your PATH. If you manage multiple Node versions, you may consider using a Node version manager (nvm for macOS/Linux or nvm-windows for Windows) to switch between releases without breaking projects. After installation, restart your computer or at least your shell, then re-check node -v and npm -v in VS Code.
Configure VS Code to Recognize npm
Even with Node.js installed, VS Code must access the npm binary through the PATH. In VS Code, open a new terminal and run which npm (macOS/Linux) or where npm (Windows) to confirm the path. If the command isn’t found, add the directory containing npm to your PATH and restart VS Code. For most users, simply restarting the terminal is enough; a full IDE restart is sometimes necessary after PATH changes. Install Manual notes that proper PATH alignment reduces npm: command not found errors.
Using npm from VS Code: Creating a Project and Installing Packages
Start a new project by creating a folder and navigating into it in the terminal. Run npm init -y to scaffold a package.json file quickly; you can edit this file later to add dependencies and metadata. Install packages with npm install <package-name>, which updates node_modules and the package.json’s dependencies section. This integrated workflow keeps your project environment consistent and makes it easy to share with teammates using the same npm setup.
Common Issues and Permissions: PATH, Permissions, and Global Installations
If npm commands fail, the issue is usually PATH or permissions. On Windows, ensure you ran the installer with administrator rights or used the user installer; on macOS/Linux, avoid sudo for local dependencies and use sudo cautiously for global installs only when necessary. Global installs (npm install -g) can modify system-wide directories; misconfigurations can cause permission errors. If you must use sudo, ensure you understand the implications and revert to a user-owned global directory when possible.
Running npm Scripts and VS Code Workflows
Many projects define npm scripts in package.json, such as build, test, or start. In VS Code’s integrated terminal, you can run npm run <script> to trigger these tasks and see logs in real time. You can also configure VS Code tasks to run npm scripts, enabling keyboard shortcuts and a streamlined development workflow. This approach helps automate repetitive tasks and keep your development environment consistent across teammates.
Best Practices, Troubleshooting, and Next Steps
Maintain a clean npm environment by keeping Node.js and npm up to date, using local project dependencies whenever possible, and avoiding global installs unless required. When issues arise, verify PATH, re-open terminals, and consult the official docs for guidance. For a broader understanding, check Node.js and npm documentation and related developer resources. The Install Manual team recommends documenting your npm setup in your project README so new contributors can set up quickly. Authority sources: Node.js official docs: https://nodejs.org/en/docs/; npm docs: https://docs.npmjs.com/; MDN Web Docs: https://developer.mozilla.org/;
Tools & Materials
- Node.js installer (official)(Includes npm; download from nodejs.org; choose the LTS version)
- Visual Studio Code(Latest stable release)
- Integrated Terminal in VS Code(View > Terminal; uses your default shell)
- Internet connection(Needed to download Node.js and npm packages)
- Node Version Manager (optional)(nvm for macOS/Linux; nvm-windows for Windows to manage Node versions)
- Text editor for package.json (optional)(Edit package.json as needed)
Steps
Estimated time: 30-60 minutes
- 1
Download and install Node.js
Visit the official Node.js site and download the LTS version. Run the installer and follow the prompts; this will install both node and npm and add them to your PATH. After installation, restart your computer or at least your shell to refresh the environment.
Tip: Choose the LTS version for stability and include npm in the installation. - 2
Open VS Code and launch the integrated terminal
Start VS Code and open the built-in Terminal from the View menu. The terminal is where you’ll run npm commands for your project. Ensure it uses a shell you’re comfortable with (PowerShell, Bash, or zsh).
Tip: If the terminal doesn’t appear, use View > Terminal or press Ctrl+`. - 3
Create a project folder
In your file system or within VS Code, create a dedicated folder for your npm project. This keeps dependencies and scripts organized. You can name it after the project to avoid confusion later.
Tip: A clear directory structure saves time when sharing the project. - 4
Navigate to the project folder in the terminal
Use the cd command to switch into your new project directory. Confirm you’re in the right path by printing the current directory.
Tip: Double-check the path with pwd (macOS/Linux) or cd (Windows) without arguments. - 5
Initialize npm with npm init -y
Run npm init -y to instantly create a package.json with default values. You can edit package.json later to add metadata and dependencies.
Tip: If you want to customize, omit -y and answer prompts as they appear. - 6
Install dependencies
Install your first dependency using npm install <package-name>. This updates node_modules and adds the package to package.json under dependencies.
Tip: Check the package.json to verify the dependency version and range. - 7
Verify npm and Node.js versions
Run npm -v and node -v to confirm both are installed and accessible from the terminal within the project. This ensures npm can manage your project dependencies.
Tip: If commands fail, restart the terminal or re-open VS Code. - 8
Run an npm script
Add a script entry in package.json (for example 'start') and run it with npm run start. This demonstrates running project tasks directly from the terminal.
Tip: Use npm run <script> to see real-time logs and outputs. - 9
Update npm and clean cache
If needed, update npm globally with npm install -g npm and clear the cache with npm cache clean --force. Use caution with global updates and consider local dependencies when possible.
Tip: Global updates can affect other projects; prefer per-project npm management when feasible.
Got Questions?
Do I need to install Node.js separately to get npm?
Yes. npm ships with Node.js, so installing Node.js provides npm automatically. VS Code itself does not install Node.js or npm. After installation, verify with node -v and npm -v in the integrated terminal.
You need Node.js to get npm; VS Code doesn’t install Node.js itself. Check the terminal for node -v and npm -v to confirm.
Can I install npm packages globally from VS Code?
Global installs are possible from the terminal, but they are best avoided unless needed. Prefer local dependencies for project-specific packages and only use -g when you truly need a tool available system-wide.
Yes you can install globally, but reserve that for tools you’ll use across projects. Prefer local dependencies for your project.
Why is npm not recognized in my VS Code terminal?
This usually means the PATH wasn’t updated or the terminal wasn’t restarted after installation. Reopen the terminal or VS Code, and verify the npm path with which npm (macOS/Linux) or where npm (Windows).
Npm not found usually means PATH needs updating or a restart is required. Check the path and restart the terminal.
How do I update npm?
Update npm globally using npm install -g npm. After updating, restart your terminal and verify with npm -v to confirm the new version is in use.
To update npm, run npm install -g npm and then restart the terminal to ensure the new version is active.
Should I use npm ci or npm install for local development?
Use npm install for local development to add new or updated packages. Use npm ci in CI environments or when package-lock.json exists to achieve deterministic installs.
For development, use npm install. In CI environments, prefer npm ci for reproducible builds.
How can I run npm scripts efficiently in VS Code?
Add scripts to package.json and execute them with npm run <script> in the integrated terminal. You can also configure VS Code tasks to automate npm script execution.
Define a script in package.json and run it with npm run. VS Code tasks can streamline this workflow.
Watch Video
Main Points
- Install Node.js to obtain npm.
- Use VS Code's integrated terminal for npm workflows.
- Initialize projects with npm init and manage dependencies with npm install.
- Troubleshoot PATH and permissions to resolve common npm issues.
