[node.js] How do you reinstall an app's dependencies using npm?

Is there a simple way to reinstall all packages that my app depends on (i.e. they are in my apps node_modules folder)?

This question is related to node.js npm

The answer is


npm updated the CLI command for install and added the --force flag.

npm install --force

The --force (or -f) argument will force npm to fetch remote resources even if a local copy exists on disk.

See npm install


You can use the reinstall module found in npm.

After installing it, you can use the following command:

reinstall

The only difference with manually removing node_modules folder and making npm install is that this command automatically clear npm's cache. So, you can get three steps in one command.

upd: npx reinstall is a way to run this command without globally installing package (only for npm5+)


For Windows you can use

(if exist node_modules rmdir node_modules /q /s) && npm install

which removes node_modules directory and performs npm install then. Removal before install assures that all packages are reinstalled.


The right way is to execute npm update. It's a really powerful command, it updates the missing packages and also checks if a newer version of package already installed can be used.

Read Intro to NPM to understand what you can do with npm.


npm ci

Alternatively, as of npm cli v6.5.0 you can use the backronym:

npm clean-install
Sources:

https://github.com/npm/cli/releases/tag/v6.5.0 https://github.com/npm/cli/commit/fc1a8d185fc678cdf3784d9df9eef9094e0b2dec


Most of the time I use the following command to achieve a complete reinstall of all the node modules (be sure you are in the project folder).

rm -rf node_modules && npm install

You can also run npm cache clean after removing the node_modules folder to be sure there aren't any cached dependencies.


Follow this step to re install node modules and update them

works even if node_modules folder does not exist. now execute the following command synchronously. you can also use "npm update" but I think this'd preferred way

npm outdated // not necessary to run this command, but this will show outdated dependencies

npm install -g npm-check-updates // to install the "ncu" package

ncu -u --packageFile=package.json // to update dependencies version in package.json...don't run this command if you don't need to update the version

npm install: will install dependencies in your package.json file.

if you're okay with the version of your dependencies in your package.json file, no need to follow those steps just run

 npm install

Delete node_module and re-install again by command

rm -rf node_modules && npm i

You can do this with one simple command:

npm ci

Documentation:

npm ci
Install a project with a clean slate


Examples related to node.js

Hide Signs that Meteor.js was Used Querying date field in MongoDB with Mongoose SyntaxError: Cannot use import statement outside a module Server Discovery And Monitoring engine is deprecated How to fix ReferenceError: primordials is not defined in node UnhandledPromiseRejectionWarning: This error originated either by throwing inside of an async function without a catch block dyld: Library not loaded: /usr/local/opt/icu4c/lib/libicui18n.62.dylib error running php after installing node with brew on Mac internal/modules/cjs/loader.js:582 throw err DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean`

Examples related to npm

What does 'x packages are looking for funding' mean when running `npm install`? error: This is probably not a problem with npm. There is likely additional logging output above Module not found: Error: Can't resolve 'core-js/es6' Browserslist: caniuse-lite is outdated. Please run next command `npm update caniuse-lite browserslist` ERROR in The Angular Compiler requires TypeScript >=3.1.1 and <3.2.0 but 3.2.1 was found instead DeprecationWarning: Buffer() is deprecated due to security and usability issues when I move my script to another server Please run `npm cache clean` What exactly is the 'react-scripts start' command? On npm install: Unhandled rejection Error: EACCES: permission denied Difference between npx and npm?