Is the upgrade of npm for node LTS recommended? - node.js

I have installed node LTS 14.17.2 via nodenv.
npm now tells me a newer version is available:
New major version of npm available! 6.14.13 → 7.19.1
My question is: Is it recommended to upgrade npm or should I stay with the version shipped with node LTS?

The npm cli is packaged with the node.js install as a convenience, but it is maintained by a different team of folks and has its own release cadence, so it can be updated even without installing new version of Node.js.
Read up on the new features and breaking changes of npm 7 on Github's Blog post about npm 7 and think about how it may affect your programs. You can always try it and switch back to an older version if you run into problems.
Generally, I suggest checking out the changelog for npm and to understand what has been updated and use that to help you decide. If there is a new breaking change that requires a new version of node, it should be indicated in the changelog.

Related

Should I update my npm version or use the one node.js provides?

I have a project that uses node.js 14.16.0. Both me and my teammember use that version.
I use npm 6.14.11 and my teammember uses npm 7.x.x.
This results in the package-lock.json being different; the lockFileVersion property is 1 on my PC but 2 on theirs.
I already use nvm and am considering to add a .nvmrc so everyone always uses the same node version, but this doesn't fix the npm version issue.
I believe that it is a good idea to use the npm version that the installed node.js version provides. If the next big LTS release uses a new npm version, the project will switch to that. But on NPM's site they say:
npm is a separate project from Node.js, and tends to update more frequently. As a result, even if you’ve just downloaded Node.js (and therefore npm), you’ll probably need to update your npm. Luckily, npm knows how to update itself!
Which makes me believe I should always update.
But they also say:
Node.js has lots of versions! To use Node.js, and therefore npm, effectively, you’ll want to make sure that you are on a version that is supported by the Node.js team. In general, you should use the version of Node.js labelled “LTS”.
Which makes me believe I shouldn't update and just use the one node.js provides.
What is the best practice?
npm has a concept of LTS. They used to tag a release lts so you could npm install -g npm#lts and get the latest lts version, but alas, no more.
npm will continue to support any major version of npm as long as it shipped with a version of node that is still supported. So they will support npm#6 until 14 goes EOL because npm#6 shipped with version 14.
That said, npm#7 is the current version of npm and it too will be supported on 14 as well for as long as 14 is supported.
If you don't want to force your coworker to update, npm#6 will continue to receive updates as long as Node.js 14 is supported. I would recommend updating to the latest npm#6 with npm install -g npm#6 though. Either version (npm#6 or npm#7) should work just fine. You just need to pick one with your coworker to avoid the package-lock.json churn (or not care about the lockfile churn).

Proper method to get the latest npm on macOS?

When I did npm -v it showed version 7.something.
I just wanted to make sure I have the latest available, so I did npm install -g npm.
It seemed to work OK (it did go through a install/upgrade process) but when I now do npm -v it says 6.14.9.
What is the 'correct' or proper way to get the latest npm on macOS? And I mean in a global way (for my entire coding environment) so that any NodeJS project in any directory will universally use the latest npm.
FYI I'm using macOS Catalina 10.15.6.
npm 7 ships with Node.js 15.x but is not yet the default latest within the npm registry. Confusing! If you want the latest 7.x version of npm, you need to specify that you want version 7: npm install -g npm#7. Otherwise, it will give you the latest 6.x release.
I recommend using nvm to manage your node versions. It allows switching between projects with different versions without running into version issues.
With it, you can use nvm install node to install the latest one, or nvm ls-remote to list available versions for install.

Are there differences between the node packages installed by different versions of npm?

There are 2 versions of node.js - LTS and latest current version. When using npm install to install packages, are the packages installed independent of the node.js being used? Do different node.js versions install different versions of the packages?
No they don't. When you install a npm package, it has its own version but of course package's version and node's version affect the usability of these packages.So, you need to delete old version of node from your system files. One more thing, please do not install npm packages global.Because when you do that, next time maybe you can use it in a other project but when it is updated by creater, you won't be able to have new updates and features or as I said before it can't be compatible with the new version of node.

Latest compatible version for NPM and node

I am using nodist version 0.8.8 which is the latest one. By using this I installed latest node version 10.7.0 and latest NPM version 6.1.0. I assured it by reading the following document.
https://nodejs.org/en/download/releases/
Nw I surfed in Google to find whether NPM 6.2.0 is available? If it is I want to know the corresponding node version for it.
Node.js and NPM versions aren't directly connected, otherwise they would have matching versions.
Semantic versioning assumes that minor versions don't introduce breaking changes:
Given a version number MAJOR.MINOR.PATCH, increment the:
MAJOR version when you make incompatible API changes,
MINOR version when you add functionality in a backwards-compatible manner, and
PATCH version when you make backwards-compatible bug fixes.
This means that if NPM 6.1.0 works with Node 10.7.0, NPM 6.2.0 works with it, too.
Node version requirements are usually listed in package.json engines section, which can be checked locally or in GitHub repository.
npm package.json doesn't contain this section, so actual Node version that is suitable for it has to be deduced.
npm code base currently uses ES6 but no higher. Latest Node 6 release covers 99% of ES6 spec, it's expected that NPM 6.2.0 is fully workable with Node 6.14 or higher. Generally, it's certain that latest even major version (Node 10, as of now) doesn't have problems with latest NPM release.
You can use nvm which is node version manager
With nvm you have the option to install the latest npm compatible with your currently installed node
use this link to install nvm:
https://github.com/creationix/nvm
Node and npm are independent tools. You can very well install different versions of either.
Use
npm i -g npm#latest
to get the latest npm installed with your node.
use node -v and npm -v to get respective version informations.

Why does Node.js's Mac Package ship with old version of npm? any issues?

I just installed the current version of node (3/14/16) 4.4.0 directly from Node.js via a Mac Package (the new suggested way, previously I installed via Homebrew).
I'm curious if anyone knows why the package ships with npm version 2.14.20, the book I'm going through suggests updating npm manually with the command
sudo npm install npm -g
The version I see is now 3.8.1, that's quite a large difference hence my question, is it safe/smart to be this far ahead of what Node.js is officially putting out with their Mac package file?
EDIT:
It appears it's common for Node's recommended v4.x install to come with npm 2.x, the question that remains is, will there be any negative side effects of using the newest npm but an older version of node?

Resources