Node update a specific package - javascript

I want to update my Browser-sync without updating all my node packages. How can I achieve this? My current version of Browser-sync does not have the Browser-sync GUI :(
├─┬ browser-sync#1.9.2
│ ├── browser-sync-client#1.0.2

Most of the time you can just npm update (or pnpm update or yarn upgrade) a module to get the latest non breaking changes (respecting the semver specified in your package.json) (<-- read that last part again).
npm update browser-sync
-------
pnpm update browser-sync
-------
yarn upgrade browser-sync
Use [p]npm|yarn outdated to see which modules have newer versions
Use [p]npm update|yarn upgrade (without a package name) to update all modules
Major version upgrades:
In your case, it looks like you want the next major version (v2.x.x), which is likely to have breaking changes and you will need to update your app to accommodate those changes. You can install/save the latest 2.x.x by doing:
npm install browser-sync#2 --save-dev
-------
pnpm add browser-sync#2 --save-dev
-------
yarn add browser-sync#2 --dev
...or the latest 2.1.x by doing:
npm install browser-sync#2.1 --save-dev
-------
pnpm add browser-sync#2.1 --save-dev
-------
yarn add browser-sync#2.1 --dev
...or the latest and greatest by doing:
npm install browser-sync#latest --save-dev
-------
pnpm add browser-sync#latest --save-dev
-------
yarn add browser-sync#latest --dev
Note: the last one is no different than doing uninstall followed by install like this:
npm uninstall browser-sync --save-dev
npm install browser-sync --save-dev
-------
pnpm remove browser-sync --save-dev
pnpm add browser-sync --save-dev
-------
yarn remove browser-sync --dev
yarn add browser-sync --dev
The --save-dev part is important. This will uninstall it, remove the value from your package.json, and then reinstall the latest version and save the new value to your package.json.

Use npm outdated to see Current and Latest version of all packages.
Then npm i packageName#versionNumber to install specific version : example npm i browser-sync#2.1.0.
Or npm i packageName#latest to install latest version : example npm i browser-sync#latest.

NPM
Update Specific Package to the Latest Version:
npm update browser-sync
Update a Package By Version:
npm view browser-sync versions (view package version)
npm install browser-sync#2
Update all packages to the latest versions:
npm outdated (this checks the registry to see if any installed packages are currently outdated)
npm update --save/--save-dev (updates and saves dependencies in package.json)
Run a security audit for all the packages:
npm audit (submits a description of the dependencies configured in your project to your default registry and asks for a report of known vulnerabilities)
npm audit fix (fix vulnerabilities)
Yarn
Updates all packages to the latest version:
yarn upgrade
Updates specific package to the latest version:
yarn upgrade browser-sync
Updates specific package to specific version:
yarn upgrade browser-sync#^2
Pnpm
Updates all dependencies, adhering to ranges specified in package.json:
pnpm up (alias of pnpm update)
Updates all dependencies, ignoring ranges specified in package.json:
pnpm up --latest
Updates browser-sync to the latest version on v2:
pnpm up browser-sync#2
Updates all dependencies under the #babel scope:
pnpm up "#babel/*"

The legacy-peer-deps command can be helpful as well, especially if you're dealing with some dependency issues and whatnot.
Example:
If the package is ngx-multi-window and it's on version 0.3.1
You would run: npm install ngx-multi-window#0.3.2 --legacy-peer-deps

Related

Installing #angular/cli at version 9 but then reporting version 7

I am trying to update my global version of angular/cli to version 9, but after running the steps below I am still seeing version 7 installed.
Step 1
npm uninstall -g #angular/cli
Step 2
npm cache clean --force
also tried
npm cache verify
Step 3
npm install -g #angular/cli#latest
It uninstalls fine as when I run ng --version after the uninstall I do not see version of CLI installed. Yet, running this again after step 3 I see version 7 installed.
You have updated it globally. Have you tried removing node_modules in project folder ?
rm -rf node_modules
npm uninstall --save-dev angular-cli
npm install --save-dev #angular/cli#latest
npm install

how to npm install only devDependencies with node 8.7.x?

The usual way of installing only devDependencies was to use npm install --only=dev (or --only=production if you want only dependencies).
This doesn't work anymore in 8.7. If I run this command, npm will try installing all dependencies. Or at least, it runs a /usr/bin/git ls-remote -h -t on packages that are not in devDependencies. Those packages being in private git repos, the npm install fails for me.
This didn't happen until I upgraded to 8.7.0, from 7.4.0
The npm cli documentation still shows the old way of doing it though.
Is there a new syntax for that option?
From the output of npm help install:
npm install (in package directory, no arguments):
Install the dependencies in the local node_modules folder.
In global mode (ie, with -g or --global appended to the command), it installs the current package context (ie, the current working directory) as a global package.
By default, npm install will install all modules listed as dependencies in npm help 5 package.json.
With the --production flag (or when the NODE_ENV environment variable is set to production), npm will not install modules listed in devDependencies.
So it seems you can install only dependencies with --production; not sure if there's a way to only install devDependencies.

c9.io - npm installs outdated packages

I have a workspace on c9.io, and I am using node.js. I am trying to update socket.io from 0.9.17 to the latest version. However, whenever I run the command npm update socket.io it installs the same version. How can I fix this?
To install the latest available package:
npm install <package>
To install a version directly (no need to uninstall first):
npm install <package>#<version>
If you're not sure what versions of a package are available, you can use:
npm view <package> versions
Don't forget the --save flag to add dependencies to your package.json file.
Source: How do I install a previous version of an npm package?
About npm update
However, if app's package.json contains:
"dependencies": {
"dep1": "~1.1.1"
}
In this case, running npm update will install dep1#1.1.2. Even though the latest tag points to 1.2.2, this version does not satisfy ~1.1.1, which is equivalent to >=1.1.1 <1.2.0. So the highest-sorting version that satisfies ~1.1.1 is used, which is 1.1.2.
Source: npm update - Tilde Dependencies

How update Sails.js to newest version?

How can I update my Sails.js framework (installed on OSX) to newest version using terminal/command line?
To update to the latest stable version:
npm update sails
or, if you've installed it globally, it would be:
sudo npm update -g sails
to install globally. This will overwrite any existing install.
npm update [-g] [<name> [<name> ...]]
This command will update all the packages listed to the latest version (specified by the tag config). It will also install missing packages.
If the -g flag is specified, this command will update globally installed packages.
So for you, I guess that would be: npm update sails or sudo npm -g update sails depending on how and where you installed it.

Print a list of all installed node.js modules

In a node.js script that I'm working on, I want to print all node.js modules (installed using npm) to the command line. How can I do this?
console.log(__filename);
//now I want to print all installed modules to the command line. How can I do this?
If you are only interested in the packages installed globally without the full TREE then:
npm -g ls --depth=0
or locally (omit -g) :
npm ls --depth=0
Use npm ls (there is even json output)
From the script:
test.js:
function npmls(cb) {
require('child_process').exec('npm ls --json', function(err, stdout, stderr) {
if (err) return cb(err)
cb(null, JSON.parse(stdout));
});
}
npmls(console.log);
run:
> node test.js
null { name: 'x11', version: '0.0.11' }
list of all globally installed third party modules, write in console:
npm -g ls
in any os
npm -g list
and thats it
Generally, there are two ways to list out installed packages - through the Command Line Interface (CLI) or in your application using the API.
Both commands will print to stdout all the versions of packages that are installed, as well as their dependencies, in a tree-structure.
CLI
npm list
Use the -g (global) flag to list out all globally-installed packages. Use the --depth=0 flag to list out only the top packages and not their dependencies.
API
In your case, you want to run this within your script, so you'd need to use the API. From the docs:
npm.commands.ls(args, [silent,] callback)
In addition to printing to stdout, the data will also be passed into the callback.
Why not grab them from dependencies in package.json?
Of course, this will only give you the ones you actually saved, but you should be doing that anyway.
console.log(Object.keys(require('./package.json').dependencies));
for package in `sudo npm -g ls --depth=0 --parseable`; do
printf "${package##*/}\n";
done
As the end of 2021, there are few obvious way to do it, and a part as the only one give on the answer above this is a complete list.
The Node.js Documentation is actually pretty well explained regarding the matter, this is a collective list of the main commands.
All Commands will run the list of installed modules Locally. In order to run global level just add a -g flag at the end of the statement.
See the version of all installed npm packages, including their dependencies.
❯ npm list
>>> /Users/joe/dev/node/cowsay
└─┬ cowsay#1.3.1
├── get-stdin#5.0.1
├─┬ optimist#0.6.1
│ ├── minimist#0.0.10
│ └── wordwrap#0.0.3
├─┬ string-width#2.1.1
│ ├── is-fullwidth-code-point#2.0.0
│ └─┬ strip-ansi#4.0.0
│ └── ansi-regex#3.0.0
└── strip-eof#1.0.0
Get only your top-level packages
npm list --depth=0
Get the version of a specific package by specifying its name.
npm list <package-name>
See what's the latest available version of the package on the npm repository
npm view <package-name> version
Install an old version of an npm package using the # syntax
npm install #
npm install cowsay#1.2.0
Global package
npm install -g webpack#4.16.4
Listing all the previous versions of a package
npm view cowsay versions
[ '1.0.0',
'1.0.1',
'1.0.2',
'1.0.3',
'1.1.0',
'1.1.1',
'1.1.2',
'1.1.3',
....
]
Update all the Node.js dependencies
Install new minor or patch release
npm update
Install new minor or patch release but not update package.json
npm update --no-save
To discover new releases of the packages, this gives you the list of a few outdated packages in one repository that wasn't updated for quite a while
npm outdated
Some of those updates are major releases. Running npm update won't update the version of those. Major releases are never updated in this way because they (by definition) introduce breaking changes, and npm wants to save you trouble.
To update all packages to a new major version, install the npm-check-updates package globally:
npm install -g npm-check-updates
ncu -u
This will upgrade all the version hints in the package.json file, to dependencies and devDependencies, so npm can install the new major version
Dev Dependency
Install in development dependencies.
npm install <package-name> -D
npm install <package-name> --save-dev # same as above
Avoid installing those development dependencies in Production with
npm install --production
Uninstalling npm packages
npm uninstall <package-name>
npm uninstall -g <package-name> # globally uninstall
Uninstall a package and ** remove the reference in the package.json**
npm uninstall <package-name> -S
npm uninstall <package-name> --save # same as above
Some commands with global flag examples.
npm list -g
npm list --depth=0 -g
npm list <package-name> -g
npm view <package-name> version -g
Additional Commands
Answer by #prosti
Documentation
Find the installed version of an npm package
Install an older version of an npm package
Update all the Node.js dependencies to their latest version
Semantic Versioning using npm
Uninstalling npm packages
npm global or local packages
npm dependencies and devDependencies
The npx Node.js Package RunnerTABLE OF CONTENTS

Categories

Resources