To update all Node.js modules manually:
- Open console with administrative permissions
- Go to Node.js installation folder:
cd C:\Program Files\nodejs
- Update npm:
npm i npm@latest
- Go to modules folder:
cd C:\Program Files\nodejs\node_modules\npm
- Install all desired modules:
npm i %MODULE_NAME%@latest
- Install update manager:
npm i npm-check@latest -g
- Available updates for locally installed modules:
npm-check -u
- Available updates for globally installed modules:
npm-check -u -g
- Recursive update of all locally installed modules:
npm update --depth 9999 --dev
- Recursive update of all globally installed modules:
npm update --depth 9999 --dev -g
- Clear the cache:
npm cache clear --force
To update all Node.js modules automatically:
- Create a package.json:
{
"_cmd-update-all-modules": "npm run update-all-modules",
"scripts": {
"create-global-node-modules-folder": "if not exist \"%appdata%\\npm\\node_modules\" mkdir %appdata%\\npm\\node_modules",
"npm-i-g": "npm i npm@latest -g",
"npm-check-i-g": "npm i npm-check@latest -g",
"npm-check-u-l": "npm-check \"C:\\Program Files\\nodejs\\node_modules\\npm\" -y",
"npm-check-u-g": "npm-check \"C:\\Program Files\\nodejs\\node_modules\\npm\" -y -g",
"npm-deep-update-l": "npm update --depth 9999 --dev",
"npm-deep-update-g": "npm update --depth 9999 --dev -g",
"npm-cache-clear": "npm cache clear --force",
"update-all-modules": "npm run create-global-node-modules-folder && npm run npm-i-g && npm run npm-check-i-g && npm run npm-check-u-l && npm run npm-check-u-g && npm run npm-deep-update-l && npm run npm-deep-update-g && npm run npm-cache-clear"
}
}
- Specify all desired modules to be installed in the
scripts
section
- Make sure the folder with Node.js, e.g.
C:\Program Files\nodejs
, is added to the PATH
through the Environment Variables
- Copy package.json to the folder with Node.js from the step #3
- Open console with the administrative permissions
- In the console, go to the folder with package.json from the step #3
- Execute
npm run update-all-modules
Both of these approaches allow you keeping all Node.js modules updated to the latest version, wherever it is installed locally or globally.
To run this package.json, call npm run update-all-modules
, stored as a hint inside of the _cmd-update-all-modules
property.