Same EXE of NPM has a different version on a different machine - node.js

When I run "FullPathHere\npm.exe" -v on my dev machine I get 3.4.0.
When I copy that file to my build machine and run that (using the full path) I get 2.14.12.
Which is better than the installed version (which is 2.7.4), but not the V3 that I need.
Why is the same EXE not giving me the same version number?

What file are you actually copying? There is no such thing as npm.exe in the standard Node install for Windows. There is npm.cmd, which is a batch script that ultimately calls the npm CLI which runs inside of the Node engine.
So to answer your question, it seems to me like you are simply copying the batch script, which simply uses your environment variables to execute whatever installed version of NPM you have.

Turned out I needed to use npm to update npm.
Once I did that, it updated to the latest version.

Related

Is there a way to install different node version using npm in windows?

Because of our company policies I cannot install nvm on my machine to have multiple node versions. Is there any npm package using which I can install and switch to different versions of node ?
I have a build tool for a proprietary system that needs an old node version.
I just downloaded and unzipped that version into a folder and run a batch script on the console to put the old node as the first %PATH% entry. After running the batch script all node calls use the old version

Node.js with Npm standard installation vs global installation of Npm

I've installed node.js v8.11.3 from their website, and it comes with npm v5.6 built-in.
Those files are in my "program files\nodejs" folder.
But recently I got aware that I can run:
npm install -g npm #"some version (upgrade or downgrade)"
and another version will be installed globally and those files will by in my "%appdata%\npm\node_modules\" folder.
Question1:
If I do this, what happens when I run the next npm command on VSCode Terminal? Which version would I be using then? Will the global version override the buil-in version?
Question 2:
And also, what happens if I install npm locally in one of my projects? Does the local version alsos override the built-in version? Does it override any global version as well?
Question 3:
It feels weird to use npm to install npm. Is this common?
Thanks.
Question 1: If I do this, what happens when I run the next npm command on VSCode Terminal? Which version would I be using then? Will the global version override the built-in version?
When you install software on Windows and attempt to use a command from the console, it takes the name of the command you're running and looks in your Windows' PATH Environment Variable for the list of folders to look for when you run a command. If you were to run npm install -g npm like you said, the version of NPM you ran when it came to your terminal would be the first version that appears in your PATH Environment Variable.
Question 2: And also, what happens if I install npm locally in one of my projects? Does the local version also override the built-in version? Does it override any global version as well?
Since your PATH Environment Variable likely doesn't extend to the node_modules folder in your project, it likely wouldn't change anything. Locally installed node modules are local in nature, meaning they rarely interact with anything outside of their folder, they have to be called.
Question 3: It feels weird to use npm to install npm. Is this common?
I can't say it is common. I doubt most node developers install npm on its own very often. And if they do, they likely don't do it through an already working npm. However, you can update all of your installed packages through npm, including npm itself, using npm update.
Basically according to the doc i would have one answer for the two questions :
If you’re installing something that you want to use in your program, using require('whatever'), then install it locally, at the root of your project.
If you’re installing something that you want to use in your shell, on the command line or something, install it globally, so that its binaries end up in your PATH environment variable.
the doc here

node-v59-linux-x64/grpc_node.node is missing

I am trying to use Firebase admin SDK in my server. When I deploy I get the error I am missing file node-v59-linux-x64/grpc_node.node in firebase-admin node_module map. I added "grpc": "1.7.1" in my package, but I still do not get that file after NPM update. I get an older version, node-v57. I also checked this path https://registry.npmjs.org/grpc/-/grpc-1.7.1.tgz, but I could not locate the file. I deleted my node_modules map and ran npm install again, still no node-v59.
How/where can I download that file? Is there any one who can put the file here so I can manually add it?
Error: Cannot find module
'/data/app/node_modules/grpc/src/node/extension_binary/node-v59-linux-x64/grpc_node.node'
This kind of problem is usually caused by installing the library on one system, then deploying and running it on a different system that requires a different binary file.
The simplest solution to this problem is to run npm rebuild after deployment on the system you deployed on.
Alternatively, if npm rebuild is not an option, you can pre-install the binary for the system you are deploying on by running npm install with some extra options. The --target argument allows you to install for a different version of Node. An argument of --target=9.0.0 installs the binary for Node 9 (only the major version has to match). The --target_platform argument allows you to install for a specific operating system: windows, linux, or darwin (Mac). The --target_arch argument lets you install for a different processor architecture: ia32, x64, or arm. And finally, the --target_libc argument lets you select binaries built for a different libc: glibc or musl (for Alpine Linux).
So, in your case, you should be able to get that binary by running
npm install --target=9.0.0 --target_platform=linux --target_arch=x64
I had the same problem. You can download the file here: https://storage.googleapis.com/grpc-precompiled-binaries/node/grpc/v1.7.1/node-v59-linux-x64.tar.gz
This helped in my case, based on #murgatroid99’s answer:
npm rebuild --target=8.1.0 --target_platform=linux --target_arch=x64 --target_libc=glibc --update-binary
It downloads the required binary to your node_modules/grpc directory.
I run macOS X on my dev machine and I’m deploying to AWS Lambda; this keeps both runtime versions installed, which means I can develop and test locally and then deploy to Lambda.

Multiple instances of node.js on one machine and npm

Today I'm installed Node.js first time on my Fedora 24 via downloading tar with latest version, then it was unpacked in some directory on my computer.
Next, I'm tried to install globally package http-server for playing with it. But access denied error occurs. It happens because on my Fedora already installed nodejs as dependency of some other packages, well, do not care about it.
And npm-cli.js executed via node, which it finds via env node command, and it finds system node, but I need to execute npm by my node, which installed in some other directory.
How to do this?
Two solutions include:
Using nvm
Manually changing the order of your $PATH so that the path for the version of node you want to use for your session comes before the path for the system copy.

Is NPM dependent on the OS of a computer?

Is it possible to copy a set of NPM installed files and associated files from a Mac computer to a Windows computer, and for all those files to work?
For example, transfering Node.js files with some other NPM files from Mac to Windows, then running node app.js in that directory (on the Windows Command Prompt).
Thanks! :)
The binary, npm, that you install is platform dependent, as is node.js. That's why there are different releases for each platform available on the download site.
For the most part, your project files are platform independent. For example, most of your JavaScript files will all be used by node.js and work just fine without having to worry about what platform you are on because the system details will be dealt with by node.js itself.
However, some modules are platform dependent. For example, anything that uses node-gyp will try to compile on your platform whenever the module is installed by npm. You do not have to worry about that though because it is handled by npm, that's why you're using a package manager.
Copying node_modules can be done; but it's more often than not better and easier to just run npm i on whatever machine is going to be running your application. You can avoid having to worry about version problems using something like npm shrinkwrap which will lock down the version of a package that your module depends on.
NPM packages that contain native addons/dependencies are tied to the OS + NodeJS version and have to be rebuilt specifically for the system you intend to use them on. This is why you're seeing the error mentioning bson.node, it is a native addon that has to be rebuilt, this can be done with the npm rebuild command.

Resources