Export Import npm Packages

I would like to reinstall npm from scratch. I want to reinstall packages already installed globally in npm after reinstallation. What would be a safe (and not manual) way to export and import globally installed modules?

Implementation note: my old npm also required sudo for global installations, so I am not trying to reuse the same directory, instead of the new npm installing the same package list as the old one.

+4
source share
2 answers
npm ls -g --depth=0

( ), . npm install, ( , / ...)

+3

TL;DR

# Export
npm list --global --parseable --depth=0 | sed '1d' | awk '{gsub(/\/.*\//,"",$1); print}' > path/to/npmfile

# Import
xargs npm install --global < path/to/npmfile

, , , / NPM.

npm list :

$ npm list` --global --depth=0

/usr/local/lib
β”œβ”€β”€ api-designer@0.1.2
β”œβ”€β”€ bower@1.7.9
β”œβ”€β”€ browserify@13.1.0
β”œβ”€β”€ grunt@1.0.1
β”œβ”€β”€ gulp@3.9.1
β”œβ”€β”€ kong-dashboard@1.1.2
β”œβ”€β”€ npm@3.10.9
β”œβ”€β”€ typescript@2.0.3
β”œβ”€β”€ vue-cli@2.3.1
β”œβ”€β”€ webpack@1.13.2
β”œβ”€β”€ webpack-dev-server@1.16.1
└── yo@1.8.4

3 :

  • └──
  • ( , )

, NPM , --parseable:

$ npm list --global --depth=0 --parseable

/usr/local/lib
/usr/local/lib/node_modules/api-designer
/usr/local/lib/node_modules/bower
/usr/local/lib/node_modules/browserify
/usr/local/lib/node_modules/grunt
/usr/local/lib/node_modules/gulp
/usr/local/lib/node_modules/kong-dashboard
/usr/local/lib/node_modules/npm
/usr/local/lib/node_modules/typescript
/usr/local/lib/node_modules/vue-cli
/usr/local/lib/node_modules/webpack
/usr/local/lib/node_modules/webpack-dev-server
/usr/local/lib/node_modules/yo

:

  • ,
  • (/usr/local/lib/node_modules/)

sed '1d', . , awk, .

$ npm list --global --parseable --depth=0 | sed '1d' | awk '{gsub(/\/.*\//,"",$1); print}'

api-designer
bower
browserify
grunt
gulp
kong-dashboard
npm
typescript
vue-cli
webpack
webpack-dev-server
yo

> /path/to/file . :

xargs npm install --global < path/to/file

arg --global, / npm.

+2

Source: https://habr.com/ru/post/1607802/


All Articles