npm使用说明

npm 使用说明

安装

npm installnpm install -g 的区别是什么?

  • npm install
    这个是根据当前目录的package.json文件安装里面涉及的依赖:
{
  "name": "node-red-project",
  "description": "A Node-RED Project",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
   "@inmation/node-red-contrib-inmation": "^1.2.0",
   "@plasma2450/node-red-contrib-homekit-bridged": "~0.3.9",
   "crypto-js": "^3.1.9-1",
   "feedparser": "^2.2.9",
   "find-my-iphone-node": "^2.0.2",
   "form-data": "^2.4.0",
   "hap-nodejs": "^0.4.47",
   "marked": "^0.6.2",
   "mkdirs": "0.0.2",
   "node-red-contrib-average": "^0.1.7",
   "node-red-contrib-baidu-face": "file:../node-red-contrib-baidu-face",
   "node-red-contrib-bigtimer": "^2.0.3",
   "node-red-contrib-bizwechat": "file:../node-red-contrib-bizwechat",
   "node-red-contrib-cheerio-function": "^1.0.0",
   "node-red-contrib-crypto-js": "~0.1.1",
   "node-red-contrib-dnspod": "~1.0.6",
   "node-red-contrib-fs-ops": "~1.5.0",
   "node-red-contrib-gaode": "file:../node-red-contrib-gaode",
   "node-red-contrib-gift": "file:../node-red-contrib-gift",
   "node-red-contrib-gps": "file:../node-red-contrib-gps",
   "node-red-contrib-gps-lite-gmiot": "file:../node-red-contrib-gps-lite-gmiot",
   "node-red-contrib-gzip": "0.0.3",
  }
}

如果没有则会报错

tester@tester-OptiPlex-3046:/opt/aa$ npm install
npm WARN saveError ENOENT: no such file or directory, open '/opt/aa/package.json'
npm WARN enoent ENOENT: no such file or directory, open '/opt/aa/package.json'
npm WARN aa No description
npm WARN aa No repository field.
npm WARN aa No README data
npm WARN aa No license field.

audited 382 packages in 2.048s
found 0 vulnerabilities

  • npm install -g
    这个是全局安装第三方库,具体位置可以通过npm root -g 查看

  • npm install --save
    这个命令产生的唯一副作用就是会把当前的安装的依赖保存在package.json之中,只有这样在我们迁移的时候才可以快速的迁移.

版本查看

  • npm -v node -v
    上面命令可以用于查看各自的版本的版本信息,如果想知道对应的文件位置可以通过 which nodewhich npm
tester@tester-OptiPlex-3046:~/.node-red$ which homebridge
/usr/local/node-v9/bin/homebridge
# 查看当前文件具体的位置
tester@tester-OptiPlex-3046:~/.node-red$ ls -all /usr/local/node-v9/bin/homebridge
lrwxrwxrwx 1 tester tester 45 4月   1 11:21 /usr/local/node-v9/bin/homebridge -> ../lib/node_modules/homebridge/bin/homebridge
tester@tester-OptiPlex-3046:~/.node-red$ npm -v
6.9.0
tester@tester-OptiPlex-3046:~/.node-red$ node -v
v9.9.0
tester@tester-OptiPlex-3046:~/.node-red$ which node
/usr/local/node-v9/bin/node
tester@tester-OptiPlex-3046:~/.node-red$ 


备份

总体来说第三方依赖库都可以通过直接安装来获取说一的依赖.剩余的就是备份一下相关的配置文件即可.例如node-red我们保存一下以下文件即可:

  • package.json
  • flow-xxx.json 默认名称会添加上hostname,所以有些机器会不一致

视频课程