一、下载安装node与npm
1、下载
2、修改 node保存位置
注:如果只像上面这样子安装的话,接下来安装的所有模块都会自动安装到C盘的node_modules里面,所以我们这里需要修改默认保存位置。
3、配置npm
4、安装nvm
二、NPM基本使用
1、npm init 在项目中引导创建一个package.json文件
npm init [-f|--force|-y|--yes]
2、npm install安装模块
// @scope表示作用域 -g或者local(不加)
npm install (with no args, in package dir)
npm install [<@scope>/]<name>
npm install [<@scope>/]<name>@<tag>
npm install [<@scope>/]<name>@<version>
npm install [<@scope>/]<name>@<version range>
npm install <tarball file>
npm install <tarball url>
npm install <folder>
alias: npm i
common options: [-S|--save|-D|--save-dev|-O|--save-optional] [-E|--save-exact] [--dry-run]
npm install @types/react@16.9.23 --save-dev // 开发环境依赖
npm install @types/react-dom@16.9.5 --save-dev // 开发环境依赖
npm install react@16.8.6 --save // 生产环境依赖
npm install react-dom@16.8.6 --save // 生产环境依赖
如:v5.0.0-beta.9 v5.0.0-alpha.32
兼容模块新发布的补丁版本:~1.1.0、1.1.x、1.1
兼容模块新发布的小版本、补丁版本:^1.1.0、1.x、1
兼容模块新发布的大版本、小版本、补丁版本:*、x
"antd": "^4.0.0-rc.1"
3、npm uninstall卸载模块
npm uninstall [<@scope>/]<pkg>[@<version>]... [-S|--save|-D|--save-dev|-O|--save-optional]
aliases: remove, rm, r, un, unlink
4、npm update 更新模块
npm update [-g] [<pkg>...]
5、npm outdated 检查已经过时的模块的Current、Wanted、Latest
// 列出过时的模块的Current版本、Wanted版本和Latest版本
npm outdated [[<@scope>/]<pkg> ...]
6、npm ls 查看安装的模块
npm ls [[<@scope>/]<pkg> ...]
aliases: list, la, ll
7、npm help 查看某条命令的详细帮助
npm help <term> [<terms..>]
npm help install
8、npm root 查看包的安装路径
npm root [-g]
9、npm config 管理npm的配置路径
npm config set <key> <value> [-g|--global]
npm config get <key>
npm config delete <key>
npm config list // 列出所有配置
npm config edit
npm get <key>
npm set <key> <value> [-g|--global]
10、npm cache 管理模块的缓存
npm cache add <tarball file>
npm cache add <folder>
npm cache add <tarball url>
npm cache add <name>@<version>
npm cache ls [<path>]
npm cache clean [<path>]
11、npm start 启动模块
npm start [-- <args>]
12、npm stop 停止模块
npm stop [-- <args>]
13、npm restart 重新启动模块
npm restart [-- <args>]
14、npm test 测试模块
npm test [-- <args>]
npm tst [-- <args>]
15、npm version 查看npm版本
npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease | from-git]
'npm [-v | --version]' to print npm version
'npm view <pkg> version' to view a package's published version
'npm ls' to inspect current package/dependency versions
16、npm view 查看模块对应的一些信息
npm view [<@scope>/]<name>[@<version>] [<field>[.<subfield>]...]
npm view <pkg> dependencies // 查看模块的依赖关系
npm view <pkg> repository.url // 查看模块的源文件地址
npm view <pkg> contributors // 查看模块的贡献者,包含邮箱地址
npm view <pkg> version // 查看模块的版本。这个是查看,对应模块的Latest版本
aliases: info, show, v
npm view babel-plugin-transform-class-properties
17、npm adduser 用户登录
npm adduser [--registry=url] [--scope=@orgname] [--always-auth]
18、npm publish 发布模块
npm publish [<tarball>|<folder>] [--tag <tag>] [--access <public|restricted>]
Publishes '.' if no argument supplied
Sets tag 'latest' if no --tag specified
19、npm access 在发布的包上设置访问级别
npm access public [<package>]
npm access restricted [<package>]
npm access grant <read-only|read-write> <scope:team> [<package>]
npm access revoke <scope:team> [<package>]
npm access ls-packages [<user>|<scope>|<scope:team>]
npm access ls-collaborators [<package> [<user>]]
npm access edit [<package>]