Node.js npm常用指令
Node.js npm常用指令运行环境
- windows cmd
- windows powershell
- IDE 中调用终端
查看 Node 版本: node —version (简写:node -v)
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> node -v
v18.15.0
运行JavaScript文件:node 文件名.js(扩展名可以省略)
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> node 1.js
hello php.cn
生成配置管理文件
package.json
:npm init -y
带参数“-y”为默认安装,不带则为分步安装PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm init -y
Wrote to C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403\package.json:
{
"name": "0403",
"version": "1.0.0",
"main": "1.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"lodash": "^4.17.21"
},
"devDependencies": {},
"description": ""
}
安装第三方npm包(当前目录):npm install package-name(简写:npm i package-name)
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm i lodashg
added 1 package in 2sg
安装第三方npm包(全局):npm install package-name —global(简写:npm i package-name -g)
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm install axios -g
added 9 packages in 1s
查看默认包目录(当前目录):npm root
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm root
C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403\node_modules
查看默认包目录(全局):npm root -g
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm root -g
C:\Users\Yinhui\AppData\Roaming\npm\node_modules
查看所有可更新的包:npm outdated
没有反馈表示当前没有更新可用PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm outdated
删除包(当前目录):npm uninstall package_name(简写:npm uni package_name)
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm uni lodash
removed 1 package, and audited 1 package in 473ms
found 0 vulnerabilities
删除包(全局):npm uninstall package_name —global(简写:npm uni package_name -g)
PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm uni axios -g
removed 9 packages in 211ms