Last updated: Apr 6, 2024
Reading time·3 min
To run NPM commands/scripts within Visual Studio Code:
Left-click on the NPM Scripts menu to expand it.
Hover over a script and click on the >
Run button to run it.
Make sure that you have a package.json
file in the root directory of your
project.
If you need to generate a package.json
file, run the following command.
npm init -y
The scripts that are shown in the NPM Scripts section in the sidebar are the
ones that are present in the scripts
object of your package.json
file.
Here is the scripts
section of my package.json
file.
{ "scripts": { "dev": "npx nodemon index.js", "test": "jest --testTimeout=30000", "clear-jest-cache": "jest --clearCache" } }
And here are the scripts in the NPM Scripts section in my sidebar.
Here is a short clip that demonstrates how to run an NPM script from your
package.json
file within VS Code.
Once you click on the Run > button, a new terminal window opens where the script is run.
If you aren't able to show the NPM Scripts menu in your left sidebar:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.Once you select the command, your editor will focus the NPM Scripts menu in the left sidebar.
Hover over a script and click on the Run > icon.
Alternatively, you can run NPM commands directly in the integrated terminal in VS Code:
Ctrl
+ Shift
+ P
on Windows and Linux.Command
+ Shift
+ P
on macOS.F1
to open the Command Palette.You can also open the terminal by using a keyboard shortcut:
Ctrl
+ ` (backtick).Ctrl
+ ` (backtick).npm
commands.npm --version npm install axios
Make sure that you have Node.js installed to be able to run NPM commands in VS Code.
I've written an article on how to install Node.js on Windows using the official installer.
You can also use the NVM package to install and manage your Node.js version:
Make sure to restart Visual Studio Code after you install Node.js.
If you get errors when running NPM commands in VS Code and you have Node.js installed, try to run VS Code as an administrator before issuing the commands.
You can learn more about the related topics by checking out the following tutorials: