Use specific versions of npm/node for different VS solutions? - node.js

I have a VS 2015 solution which requires I have the newest version of nodejs installed externally, and added to the External Web Tools path. (web project using a packages.json and gulp file to retrieve css/js modules and compile ssas at build time)
I also have older solutions that uses older versions of modules, and worked with the default versions of npm(1.4.9) and node(0.10.31). Once I installed newer nodejs externally and added to External Web Tools path, npm now throws various errors. As I work through errors I tend to to end up at github issues where someone had opened an issue and the responses were "you're using too old a version of node/npm".
In an ideal world we'd work through the old projects to get them on newer versions but this has a larger impact than is feasible.
Is there a way to specify that some projects use the default node/npm while other projects use the newer? I.e. a way to make the External Web Tools paths a proj/sln level setting instead of being a global Visual Studio setting.

You can use something like nvm.
In your project root directory, you would setup a .nvmrc and you would just set the version number in there. For example my file would have v10.9.0, and then I would just go into the directory and from the command line type the following:
nvm use
You can also have nvm set your npm version as well. See this answer

You can use Node Version Manager(NVM) to solve your problem
NVM allow to run multiple node version in single machine, You can switch on any node verion using NVM
for more information you can refer
https://medium.com/appseed-io/how-to-run-multiple-versions-of-node-js-with-nvm-for-windows-ffbe5c7a2b47

Related

Upgrading node version individually for each project

I have two projects on-going, in one I need node v8 (yes, I know, it's very behind), and one in node v14. right now, across my local machine, globally, I have node v8 installed, but if I want to update my one project to node v14, and keep one at v8, is this possible? Can I just run npm update on my one project and it will keep v8 on my other, or will it do it globally?
Thanks in advance!
We successfully use nodenv for managing node versions between projects. It allows many versions to be available simultaneously. Once set up you add a .node-version file to the root of your project and this will be the version accessed by nodenv.
There is also nvm node version manager, which many use, though I don't have much experience with it.

Run NodeJS programs all requiring different versions of node

I know this is an old problem, and I've gotten so far with other answers, so I'm using nvm for windows, I have my Node V11 and Node V12 versions installed, but when I do:
nvm use 11.15
The windows User Escalation popup comes up saying "Do you want to change the settings for CMD.exe?".
Ideally, I'd want to just switch the environment of my current process (from VSCode Terminal) or possibly use the nvm tool in a batch file to ensure that I can run different NodeJS solutions side-by-side on the same machine i.e. using different versions of node at the same time. Is this possible without requiring admin escalation?
Thanks

gulp integration in Visual Studio 2017 not working

I'm attempting to get gulp integration into Visual Studio 2017. It's working on the command line. The Task Runner Explorer in VS2017 is telling me Failed to load. See output window.
The Output Window is telling me the following:
Failed to run "<ProjectPath>\Gulpfile.js"...
cmd.exe /c gulp --tasks-simple
<ProjectPath>\node_modules\node-sass\lib\binding.js:15
throw new Error(errors.missingBinary());
^
Error: Missing binding <ProjectPath>\node_modules\node-sass\vendor\win32-x64-47\binding.node
Node Sass could not find a binding for your current environment: Windows 64-bit with Node.js 5.x
Found bindings for the following environments:
- Windows 64-bit with Node.js 8.x
This usually happens because your environment has changed since running `npm install`.
Run `npm rebuild node-sass --force` to build the binding for your current environment.
I attempt to run npm rebuild node-sass --force, only to be told Error: Can't find Python executable "C:\Python36\python.EXE", you can set the PYTHON env variable., which I confirmed existed.
I'm not sure how much farther I want to go down this rabbit hole. It appears to be a VS issue since everything works as expected on the command line. I'd like to get the gulp integration with VS working correctly.
Point your VS tools to the node installation on your path.
I can see in the error that there a version discrepancy between 5.x and 8.x - with VS likely being the older one (since it ships with pre-packaged and outdated node) and is taking execution precedence with the default setup.
I'm guessing you installed node-sass via your 8.x (external command line) instance but VS is trying to execute your gulp tasks via your VS's internal 5.x. node-sass leverages node-gyp to build a binary via installation scripts, and there will be incompatibilities across versions. In other words, this package, and many others that build binaries, are specifically tailored to the version of node it was installed against. To summarize, everything in node_modules/.bin is built against 8.x but is actually running on 5.x when you do so through Visual Studio.
Fear not, this is easily solved. Check out this answer for some historical context on this long running issue that many face. Basically, you want $(PATH) to be at the top of this list so your OS installation is always used...
Once you do this (just to be safe) - blow away node_modules, reinstall, and happy coding. VS really needs to stop shipping with pinned versions of node...
I ran into this problem on both Visual Studio 2017 and 2019. Apparently my Node install wasn't registered in the PATH variable (and I don't have permission to modify this on my work machine), so I manually added the link to Node at C:\Program Files\nodejs, moved that to the top location and that worked for me.
This drove me nuts until I found one more missing thing. Even if you configured everything as in the other answers you can get the same error, possibly if your user folder is not on the same drive as where Node is installed. Then also add %APPDATA%\npm to the external tools paths so globally installed Node tools will be found too.
So all in all the external tools config in VS should contain these two paths first, in this order:
C:\Program Files\NodeJS (or where you have Node installed).
%APPDATA%\npm
For me without #2 everything was working from the command line everywhere but not in VS. With it added everything now works in VS too.

VS Code, change NodeJS version for debugger

I want to change NodeJS version from 4.5.0 to 7.7.2 for VS Code specifically for different projects.
I am using nvm on Mac, and I have two versions stated above. They are for different projects.
Even though I can change from terminal with nvm, VS Code uses default version. I need to change the default version every time and completely restart the VSCode.
Is there a way to alter configuration so it picks up the version I wanted
both for in-app terminal and for running project?
After VS Code 1.21, there is a better solution than the original answer.
You can set "runtimeVersion": "7.7.2" and if you have nvm/nvs installed, it will be able to find that version of Node. Details: https://code.visualstudio.com/updates/v1_21#_node-debugging
--- Original answer ---
In your launch config, you can set a path to a Node executable from nvm like this: "runtimeExecutable": "/Users/me/.nvm/versions/node/v7.7.1/bin/node"

Where and how can I get a certain version of NodeJs?

I'll be attending a MS course tomorrow and I'm supposed to install NodeJs version 0.12.7. However, when I follow the link provided, I only get a directory listing of a bunch of files. And I'm certainly not sure which one(s) I need (I'm on Win 8).
I also tried with their front page but the versions advertised there are v.4.2.2 and v.5.0.0, which surprised me (cf. v.0.12.7). When I went to the downloads' section, I got totally confused by the overwhelming number of options, platforms, versions etc.
I trust my godlike ability to pick just the wrong option as well as my superpower of confusing everything to the edge of ridiculousness, so instead of cursing my rectum off, I prefer to ask straight how to obtain the requested version (v.0.12.7 for Win 8).
I would suggest nvm, it's great for node version management and installing any particular version of node you would like. https://github.com/creationix/nvm
If you're running 32-bit Windows, then you want the node-v0.12.7-x86.msi file in the directory in your link.
If you're running 64-bit Windows, then you want the node-v0.12.7-x64.msi file in the x64 subdirectory.
As #Ryan McDermott suggested, nvm is good. Another option, which I like, is nodenv: https://github.com/OiNutter/nodenv.
First, install nodenv. Then, install the plugin node-build (https://github.com/OiNutter/node-build). Then you can do the following:
nodenv install --list # list available node versions
nodenv install 0.12.7 # install the specified version
nodenv global 0.12.7 # use the specified version of node

Resources