nodejs

  • node.js:reactNative项目所需要的代码库。

    npm

  • npm:node.js随同的第三方package包管理工具。

    nvm

  • nvm(Node Version Manager 版本管理)。管理 node.js和 npm版本。

    常用命令

    list

    作用描述

  1. 1s-MacBook-Air-5:~ a1$ nvm list
  2. v6.11.3
  3. -> v8.5.0
  4. system
  5. default -> 8.5.0 (-> v8.5.0)
  6. node -> stable (-> v8.5.0) (default)
  7. stable -> 8.5 (-> v8.5.0) (default)
  8. iojs -> N/A (default)
  9. lts/* -> lts/boron (-> v6.11.3)
  10. lts/argon -> v4.8.4 (-> N/A)
  11. lts/boron -> v6.11.3

—help

  1. Node Version Manager
  2. Note: <version> refers to any version-like string nvm understands. This includes:
  3. - full or partial version numbers, starting with an optional "v" (0.10, v0.1.2, v1)
  4. - default (built-in) aliases: node, stable, unstable, iojs, system
  5. - custom aliases you define with `nvm alias foo`
  6. Any options that produce colorized output should respect the `--no-colors` option.
  7. Usage:
  8. nvm --help Show this message
  9. nvm --version Print out the installed version of nvm
  10. nvm install [-s] <version> Download and install a <version>, [-s] from source. Uses .nvmrc if available
  11. --reinstall-packages-from=<version> When installing, reinstall packages installed in <node|iojs|node version number>
  12. --lts When installing, only select from LTS (long-term support) versions
  13. --lts=<LTS name> When installing, only select from versions for a specific LTS line
  14. --skip-default-packages When installing, skip the default-packages file if it exists
  15. --latest-npm After installing, attempt to upgrade to the latest working npm on the given node version
  16. nvm uninstall <version> Uninstall a version
  17. nvm uninstall --lts Uninstall using automatic LTS (long-term support) alias `lts/*`, if available.
  18. nvm uninstall --lts=<LTS name> Uninstall using automatic alias for provided LTS line, if available.
  19. nvm use [--silent] <version> Modify PATH to use <version>. Uses .nvmrc if available
  20. --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.
  21. --lts=<LTS name> Uses automatic alias for provided LTS line, if available.
  22. nvm exec [--silent] <version> [<command>] Run <command> on <version>. Uses .nvmrc if available
  23. --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.
  24. --lts=<LTS name> Uses automatic alias for provided LTS line, if available.
  25. nvm run [--silent] <version> [<args>] Run `node` on <version> with <args> as arguments. Uses .nvmrc if available
  26. --lts Uses automatic LTS (long-term support) alias `lts/*`, if available.
  27. --lts=<LTS name> Uses automatic alias for provided LTS line, if available.
  28. nvm current Display currently activated version
  29. nvm ls List installed versions
  30. nvm ls <version> List versions matching a given <version>
  31. nvm ls-remote List remote versions available for install
  32. --lts When listing, only show LTS (long-term support) versions
  33. nvm ls-remote <version> List remote versions available for install, matching a given <version>
  34. --lts When listing, only show LTS (long-term support) versions
  35. --lts=<LTS name> When listing, only show versions for a specific LTS line
  36. nvm version <version> Resolve the given description to a single local version
  37. nvm version-remote <version> Resolve the given description to a single remote version
  38. --lts When listing, only select from LTS (long-term support) versions
  39. --lts=<LTS name> When listing, only select from versions for a specific LTS line
  40. nvm deactivate Undo effects of `nvm` on current shell
  41. nvm alias [<pattern>] Show all aliases beginning with <pattern>
  42. nvm alias <name> <version> Set an alias named <name> pointing to <version>
  43. nvm unalias <name> Deletes the alias named <name>
  44. nvm install-latest-npm Attempt to upgrade to the latest working `npm` on the current node version
  45. nvm reinstall-packages <version> Reinstall global `npm` packages contained in <version> to current version
  46. nvm unload Unload `nvm` from shell
  47. nvm which [<version>] Display path to installed node version. Uses .nvmrc if available
  48. nvm cache dir Display path to the cache directory for nvm
  49. nvm cache clear Empty cache directory for nvm
  50. Example:
  51. nvm install 8.0.0 Install a specific version number
  52. nvm use 8.0 Use the latest available 8.0.x release
  53. nvm run 6.10.3 app.js Run app.js using node 6.10.3
  54. nvm exec 4.8.3 node app.js Run `node app.js` with the PATH pointing to node 4.8.3
  55. nvm alias default 8.1.0 Set default node version on a shell
  56. nvm alias default node Always default to the latest available node version on a shell
  57. Note:
  58. to remove, delete, or uninstall nvm - just remove the `$NVM_DIR` folder (usually `~/.nvm`)
  • package.json.package.json是npm内的一个包。包括了文件的配置信息,具体包括:元数据(名称,版本),所需模块(执行依赖和开发依赖)。
  • package.lock.json.是npm的一个包。作用:

    (1)安装之后锁定包的版本,手动更改package.json文件安装将不会更新包,想更新只能使用npm install xxx@1.0.0 — save 方式更新 package.lock.json才可以。
    (2)加快了 npm install速度,因为package.lock.json文件已经记录了整个 node_modules文件夹的树状结构,甚至记录模块的下载地址,重新安装的时候直接下载文件就可以。
    综上。意义在于锁定了包的版本,确保能够避免包版本不同产生的问题。

  • package.lock.json(A)和package.json(B)的区别:B主要用来定义项目所需要的包,A在 npm install时生成一份文件,用来记录当前安装的npm package的具体来源和版本号。

    注: ‘^’ :
    放在版本号之前,表示向后兼容依赖,说白了就是在大版本号不变的情况下,下载最新版的包
    项目中引入的包版本号之前经常会加^号,每次在执行npm install之后,下载的包都会发生变化,为了系统的稳定性考虑,每次执行完npm install之后会对应生成package-lock文件,该文件记录了上一次安装的具体的版本号,相当于是提供了一个参考,在出现版本兼容性问题的时候,就可以参考这个文件来修改版本号即可。

  • node,nvm,npm

image.png

联系二:
DL (1).png