Running npm command within Visual Studio Code
Install
-
Ctrl+P, write
ext install npm script runner
- Restart VS Code
Use (two ways)
- Ctrl+R Shift+R
-
Ctrl+P, write
>npm
, selectrun script
, select the desired task
Update: Since version 1.3 Visual Studio Code has integrated terminal. To open it, use any of these methods:
- Use the Ctrl+` keyboard shortcut.
- Use the View | Toggle Integrated Terminal menu command.
- From the Command Palette (Ctrl+Shift+P), use the
View:Toggle Integrated Terminal
command.
You can run npm commands directly in terminal (ctrl + `). Make sure that terminal has cmd.exe as the shell selected.
You can default cmd.exe as your shell by following these steps.
- ctrl+Shift+p
- Type > Select Default Shell + Enter
- Select > Command Prompt ...cmd.exe
- Restart VS Code.
There might be a chance that you have install node.js while your visual studio code was open. Once node.js is install successfully, Simply close the VS Code and Start it again. It will work. Thank you
On Win10 I had to run VSCode as administrator to npm commands work.
All you need to do is to add args to the integrated terminal within 'User Settings' window.
Follow this steps below to do that:
- List item
- Go to 'User Settings'
- Search for setting named - "terminal.integrated.shellArgs.windows"
- Edit this setting by copying it to the right side.
- Add the following arg value = "/k nodevars.bat", e.g.
"terminal.integrated.shellArgs.windows": ["/k nodevars.bat"],
- Make sure that the setting named "terminal.integrated.shell.windows" is set to the value - "C:\Windows\system32\cmd.exe". If not then do that.
- Open new Terminal.
Good luck