Nemo

Nemo 关注TA

路漫漫其修远兮,吾将上下而求索。

Nemo

Nemo

关注TA

路漫漫其修远兮,吾将上下而求索。

  •  普罗旺斯
  • 负责帅就完事了
  • 写了1,495,102字

该文章投稿至Nemo社区   Js、Css、Html  板块 复制链接


[NodeJS]npm 的使用

发布于 2016/06/13 21:07 3,630浏览 0回复 3,523


安装

$ npm install express -g

npm WARN checkPermissions Missing write access to /usr/local/lib
/usr/local/lib
└─┬ express@4.13.4
├─┬ accepts@1.2.13
│ ├─┬ mime-types@2.1.11
│ │ └── mime-db@1.23.0
│ └── negotiator@0.5.3
├── array-flatten@1.1.1
├── content-disposition@0.5.1
├── content-type@1.0.2
├── cookie@0.1.5
├── cookie-signature@1.0.6
├─┬ debug@2.2.0
│ └── ms@0.7.1
├── depd@1.1.0
├── escape-html@1.0.3
├── etag@1.7.0
├─┬ finalhandler@0.4.1
│ └── unpipe@1.0.0
├── fresh@0.3.0
├── merge-descriptors@1.0.1
├── methods@1.1.2
├─┬ on-finished@2.3.0
│ └── ee-first@1.1.1
├── parseurl@1.3.1
├── path-to-regexp@0.1.7
├─┬ proxy-addr@1.0.10
│ ├── forwarded@0.1.0
│ └── ipaddr.js@1.0.5
├── qs@4.0.0
├── range-parser@1.0.3
├─┬ send@0.13.1
│ ├── destroy@1.0.4
│ ├─┬ http-errors@1.3.1
│ │ └── inherits@2.0.1
│ ├── mime@1.3.4
│ └── statuses@1.2.1
├─┬ serve-static@1.10.3
│ └── send@0.13.2
├─┬ type-is@1.6.13
│ └── media-typer@0.3.0
├── utils-merge@1.0.0
└── vary@1.0.1

npm ERR! Linux 4.4.0-24-generic
npm ERR! argv "/usr/bin/nodejs" "/usr/bin/npm" "install" "express" "-g"
npm ERR! node v4.2.6
npm ERR! npm  v3.5.2
npm ERR! path /usr/local/lib
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall access

npm ERR! Error: EACCES: permission denied, access '/usr/local/lib'
npm ERR!     at Error (native)
npm ERR!  { [Error: EACCES: permission denied, access '/usr/local/lib']
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'access',
npm ERR!   path: '/usr/local/lib' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /home/nemo/nodejs/npm-debug.log


这里需要用超级管理员的权限才能作此操作:


$ sudo npm install express -g
/usr/local/lib
└─┬ express@4.13.4
├─┬ accepts@1.2.13
│ ├─┬ mime-types@2.1.11
│ │ └── mime-db@1.23.0
│ └── negotiator@0.5.3
├── array-flatten@1.1.1
├── content-disposition@0.5.1
├── content-type@1.0.2
├── cookie@0.1.5
├── cookie-signature@1.0.6
├─┬ debug@2.2.0
│ └── ms@0.7.1
├── depd@1.1.0
├── escape-html@1.0.3
├── etag@1.7.0
├─┬ finalhandler@0.4.1
│ └── unpipe@1.0.0
├── fresh@0.3.0
├── merge-descriptors@1.0.1
├── methods@1.1.2
├─┬ on-finished@2.3.0
│ └── ee-first@1.1.1
├── parseurl@1.3.1
├── path-to-regexp@0.1.7
├─┬ proxy-addr@1.0.10
│ ├── forwarded@0.1.0
│ └── ipaddr.js@1.0.5
├── qs@4.0.0
├── range-parser@1.0.3
├─┬ send@0.13.1
│ ├── destroy@1.0.4
│ ├─┬ http-errors@1.3.1
│ │ └── inherits@2.0.1
│ ├── mime@1.3.4
│ └── statuses@1.2.1
├─┬ serve-static@1.10.3
│ └── send@0.13.2
├─┬ type-is@1.6.13
│ └── media-typer@0.3.0
├── utils-merge@1.0.0
└── vary@1.0.1


========================


-g的参数是指全局使用。#全局安装

如果去掉-g参数,那么则只有当前工程可以使用。#本地安装

新引入的框架可以在工程中这样使用:


var express = require('express');



本地安装

  • 1. 将安装包放在 ./node_modules 下(运行 npm 命令时所在的目录),如果没有 node_modules 目录,会在当前执行 npm 命令的目录下生成 node_modules 目录。
  • 2. 可以通过 require() 来引入本地安装的包。

全局安装

  • 1. 将安装包放在 /usr/local 下。
  • 2. 可以直接在命令行里使用。
  • 3. 不能通过 require() 来引入本地安装的包。


卸载

$ npm uninstall express

卸载后可以输入:

$ npm ls

查看该模块是否被卸载成功。


更新

$ npm update express

搜索

$ npm search express

...





点赞(0)

上一个文章:[NodeJS]读取文件

下一个文章:[NodeJS]第一个服务器端程序

点了个评