Is there anyway of executing the npm
command within Visual Studio Code (using f1
into >
) on Windows(10) to install packages to my folder I'm working in?
I have npm installed and I keep having to install npm packages from cmd
Install
ext install npm script runner
Use (two ways)
>npm
, select run script
, select the desired task Update: Since version 1.3 Visual Studio Code has integrated terminal. To open it, use any of these methods:
View:Toggle Integrated Terminal
command.All you need to do is to add args to the integrated terminal within 'User Settings' window.
Follow this steps below to do that:
"terminal.integrated.shellArgs.windows": ["/k nodevars.bat"],
Good luck
One reason might be if you install the node after starting the vs code,as vs code terminal integrated or external takes the path value which was at the time of starting the vs code and gives you error:
'node' is not recognized as an internal or external command,operable program or batch file.
A simple restart of vs code will solve the issue.
settings.json
.settings.json
> Edit in settings.json
%APPDATA%\Code\User\settings.json
{
"terminal.integrated.shell.windows": "C:\\Windows\\System32\\cmd.exe",
"terminal.integrated.shellArgs.windows": ["/k nodevars.bat"]
}
Same thing was happening to me after I installed Node.js. Node and npm was recognized in PowerShell and Command Prompt but not in VS Code. I fixed it by adding the Node.js install path to the system's environment PATH
variable. The node.js install path on my system was:
C:\Program Files\nodejs
Where I find the node.exe
that is needed. The user's PATH
variable already had the Node.js install path but for some reason VS Code needs the Node.js install path in the system's PATH
variables.
Windows 10 instructions:
The other answers were great but this is another way to fix it that worked for me without needing to install stuff, run as admin, or change the default settings.
VSCode User Setup
is a new installer which installs VSCode and its dependencies in directories which don't require system-level / administrator permissions to modify. This is because New VSCode runs with user privileges. Your Nodejs installation added npm's path as System variable which VSCode cannot read.
Adding NPM path to Path variable in the User variable, you will be able to run NPM from the integrated command line.
As an alternative to some of the answers suggested above, if you have powershell installed, you can invoke that directly as your terminal. That is edit the corresponding setting.json
value as follows:
"terminal.integrated.shell.windows": "C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
I find this works well as the environment is correctly configured.
Open standard terminal ctrl+p and paste this command
npm i script-runner
Need to see this logs npm should be run outside of the node repl, in your normal shell. (Press Control-D to exit.)
(To exit, press ^C again or type .exit)
C:\DW\Examples\Ang.Crud>npm i script-runner npm WARN saveError ENOENT: no such file or directory, open 'C:\DW\Examples\Ang.Crud\package.json' npm notice created a lockfile as package-lock.json. You should commit this file. npm WARN enoent ENOENT: no such file or directory, open 'C:\DW\Examples\Ang.Crud\package.json' npm WARN Ang.Crud No description npm WARN Ang.Crud No repository field. npm WARN Ang.Crud No README data npm WARN Ang.Crud No license field.
- [email protected] added 7 packages from 5 contributors and audited 7 packages in 2.955s found 0 vulnerabilities
Usage: npm
where is one of: access, adduser, audit, bin, bugs, c, cache, ci, cit, completion, config, create, ddp, dedupe, deprecate, dist-tag, docs, doctor, edit, explore, get, help, help-search, hook, i, init, install, install-test, it, link, list, ln, login, logout, ls, outdated, owner, pack, ping, prefix, profile, prune, publish, rb, rebuild, repo, restart, root, run, run-script, s, se, search, set, shrinkwrap, star, stars, start, stop, t, team, test, token, tst, un, uninstall, unpublish, unstar, up, update, v, version, view, whoami
npm -h quick help on npm -l display full usage info npm help search for help on npm help npm involved overview
Specify configs in the ini-formatted file: C:\Users\fdc.npmrc or on the command line via: npm --key value Config info can be viewed via: npm help config
[email protected] C:\Program Files\nodejs\node_modules\npm
You have to do the following 3 steps to fix your issues:
1.Download Node.js from here.
Install it and then add the path C:\Program Files\nodejs to your System variables.
Then restart your visual studio code editor.
Happy code