Blogger Information
Blog 29
fans 0
comment 0
visits 11134
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
Node.js npm常用指令
尹辉
Original
530 people have browsed it

Node.js npm常用指令

运行环境

  • windows cmd
  • windows powershell
  • IDE 中调用终端

常用指令

  • 查看 Node 版本: node —version (简写:node -v)

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> node -v
    2. v18.15.0
  • 运行JavaScript文件:node 文件名.js(扩展名可以省略)

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> node 1.js
    2. hello php.cn
  • 生成配置管理文件 package.json:npm init -y
    带参数“-y”为默认安装,不带则为分步安装

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm init -y
    2. Wrote to C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403\package.json:
    3. {
    4. "name": "0403",
    5. "version": "1.0.0",
    6. "main": "1.js",
    7. "scripts": {
    8. "test": "echo \"Error: no test specified\" && exit 1"
    9. },
    10. "keywords": [],
    11. "author": "",
    12. "license": "ISC",
    13. "dependencies": {
    14. "lodash": "^4.17.21"
    15. },
    16. "devDependencies": {},
    17. "description": ""
    18. }
  • 安装第三方npm包(当前目录):npm install package-name(简写:npm i package-name)

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm i lodashg
    2. added 1 package in 2sg
  • 安装第三方npm包(全局):npm install package-name —global(简写:npm i package-name -g)

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm install axios -g
    2. added 9 packages in 1s
  • 查看默认包目录(当前目录):npm root

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm root
    2. C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403\node_modules
  • 查看默认包目录(全局):npm root -g

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm root -g
    2. C:\Users\Yinhui\AppData\Roaming\npm\node_modules
  • 查看所有可更新的包:npm outdated
    没有反馈表示当前没有更新可用

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm outdated
  • 删除包(当前目录):npm uninstall package_name(简写:npm uni package_name)

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm uni lodash
    2. removed 1 package, and audited 1 package in 473ms
    3. found 0 vulnerabilities
  • 删除包(全局):npm uninstall package_name —global(简写:npm uni package_name -g)

    1. PS C:\Users\Yinhui\Desktop\PHP中文网23期线上班\0403> npm uni axios -g
    2. removed 9 packages in 211ms
Correcting teacher:PHPzPHPz

Correction status:qualified

Teacher's comments:
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post