NPM 的使用介绍

NPM使用介绍
    安装成功后,版本查看: npm -v
    npm 升级命令: npm install npm -g
    npm 安装模块命令: npm install <Module Name>
    例如: 安装Node.js web框架模块 express:
    npm install express

    npm 包安装分为本地安装和全局安装
    npm install express      #本地安装
    npm install express -g   #全局安装

    安装过程如果出现以下错误: 
    npm err! Error: connect ECONNREFUSED 127.0.0.1:8087
    执行以下命令解决:
    npm config set proxy null

    查看全局安装模块命令:
    npm list -g

    查看某个模块版本号:
    npm list grunt

    卸载模块命令:
    npm uninstall <Module Name>
    
    更新模块命令:
    npm update <Module Name>

    搜索模块命令:
    npm search <Module Name>
    
    ---------------------------分割线-----------------------------
    
    创建模块
    创建模块,package.json文件是必不可少的,我们可以使用NPM生成package.json文件,生成的文件包含了基本的结果

    
      $ npm init
      This utility will walk you through creating a package.json file.
      It only covers the most common items, and tries to guess sensible defaults.
      
      See `npm help json` for definitive documentation on these fields
      and exactly what they do.
      
      Use `npm install <pkg> --save` afterwards to install a package and
      save it as a dependency in the package.json file.
      
      Press ^C at any time to quit.
      name: (node_modules) runoob                   # 模块名
      version: (1.0.0) 
      description: Node.js 测试模块(www.runoob.com)  # 描述
      entry point: (index.js) 
      test command: make test
      git repository: https://github.com/runoob/runoob.git  # Github 地址 (注:这个地址换成自己的) 
      keywords: 
      author: 
      license: (ISC) 
      About to write to ……/node_modules/package.json:      # 生成地址
      
      {
        "name": "runoob",
        "version": "1.0.0",
        "description": "Node.js 测试模块(www.runoob.com)",
        ……
      }
      
      Is this ok? (yes) yes
      
    
    
    ---------------------------分割线-----------------------------
    
    完成模块创建之后,会生成相应的package.json,接下来执行以下命令在npm资源库中注册用户:
    npm adduser
    
      Username: matthewkuo
      Password: 
      Email: (this IS public) 18500735583@163.com
    
    注:Password 在输入中不会显示出来
    
    接下来通过以下命令来发布模块:
    npm publish
 对于发布过的模块,处于保护性原则,允许在24小时之内删除已发布的模块资源。命令如下:
 npm unpublish <Module Name>
原文地址:https://www.cnblogs.com/matthewkuo24/p/12859185.html