美文网首页
npm:常用命令

npm:常用命令

作者: 春暖花已开 | 来源:发表于2021-09-22 13:11 被阅读0次
    • 查看文档
    npm docs [<pkgname> [<pkgname> ...]]
    aliases: home
    
    • 检查环境
    npm doctor
    
    • 打开包对应的源码仓库
    npm repo
    
    • 打开安装的位置
    npm root
    
    • star一个库
    npm star [<pkg>...]
    
    • 查看自己喜欢的包
    npm stars [<user>]
    
    • 启动一个包
    npm start [-- <args>]
    
    {
      "scripts": {
        "start": "node foo.js"
      }
    }
    
    • 停止一个包
    npm stop [-- <args>]
    
    {
      "scripts": {
        "stop": "node bar.js"
      }
    }
    
    • 从npm包运行
    npm exec -- <pkg>[@<version>] [args...]
    npm exec --package=<pkg>[@<version>] -- <cmd> [args...]
    npm exec -c '<cmd> [args...]'
    npm exec --package=foo -c '<cmd> [args...]'
    npx <pkg>[@<specifier>] [args...]
    npx -p <pkg>[@<specifier>] <cmd> [args...]
    npx -c '<cmd> [args...]'
    npx -p <pkg>[@<specifier>] -c '<cmd> [args...]'
    alias: npm x, npx
    
    • 查看npm的用户名
    npm whoami
    
    • 查看registry信息
    npm view [<@scope>/]<name>[@<version>] [<field>[.<subfield>]...]
    aliases: info, show, v
    
    • 查看包的版本
    npm version [<newversion> | major | minor | patch | premajor | preminor | prepatch | prerelease [--preid=<prerelease-id>] | 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
    
    • 安装包
    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 <alias>@npm:<name>
    npm install <git-host>:<git-user>/<repo-name>
    npm install <git repo url>
    npm install <tarball file>
    npm install <tarball url>
    npm install <folder>
    aliases: npm i, npm add
    
    • 创建package.json文件
    npm init [--yes|-y|--scope]
    npm init <@scope> (same as `npm exec <@scope>/create`)
    npm init [<@scope>/]<name> (same as `npm exec [<@scope>/]create-<name>`)
    npm init [-w <dir>] [args...]
    
    • 列出所有安装的包
    npm ls [[<@scope>/]<pkg> ...]
    aliases: list, la, ll
    
    • 移除包
    npm uninstall [<@scope>/]<pkg>[@<version>]... [-S|--save|--no-save]
    aliases: remove, rm, r, un, unlink
    
    • 升级包
    npm update [-g] [<pkg>...]
    aliases: up, upgrade
    

    参考:

    CLI commands

    相关文章

      网友评论

          本文标题:npm:常用命令

          本文链接:https://www.haomeiwen.com/subject/fwowgltx.html