NPM 使用

NPM 使用

npm是随同NodeJS一起安装的包管理工具,通过使用npm命令,可以实现下面这些功能:

  • 允许用户从NPM服务器下载别人编写的第三方包到本地使用。
  • 允许用户从NPM服务器下载并安装别人编写的命令行程序到本地使用。
  • 允许用户将自己编写的包或命令行程序上传到NPM服务器供别人使用。

1.npm 命令安装模块

npm install <packageName>

是不是感觉到有疑问,为什么使用npm install <packageName>就可以安装模块?

其实这和ubuntu的apt-get install 命令是一样的原理,在它的背后都有一个模块仓库存在。

Node模块的安装过程是这样的:

1.发出npm install命令
2.npm 向 registry 查询模块压缩包的网址
3.下载压缩包,存放在~/.npm目录
4.解压压缩包到当前项目的node_modules目录

假设现在你在/demo路径下运行node install express命令,运行完以后,在/demo下会多出一个node_modules/文件夹,里面有一个express/ module

2.npm 命令更新已安装模块

npm update <packageName> 

3.npm 命令卸载模块

npm uninstall express

4.创建模块

$ 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: (yeqing) yeching_module        //模块名
version: (1.0.0)
description: just for test    //描述内容
entry point: (index.js)
test command: console.log("hello");
git repository:
keywords: yeching
author: yeching
license: (ISC)
About to write to C:\Users\yeqing\package.json:# 生成地址

{
  "name": "yeching_module",
  "version": "1.0.0",
  "description": "just for test",
  "main": "index.js",
  "scripts": {
    "test": "console.log()\u001b[D)\u001b[D\"\"\u001b[Dhello\");"
  },
  "keywords": [
    "yeching"
  ],
  "author": "yeching",
  "license": "ISC"
}

Is this ok? (yes)

更多内容参考:

1.npm 模块安装机制简介

2.NPM 使用介绍

posted @ 2017-01-23 18:13  叶子陪你玩  阅读(1337)  评论(0编辑  收藏  举报