我们再看一下 config(1) 链接,查看config文档,它就是一个全局设置,文档中有下面这段话:
registry
- Default: https://registry.npmjs.org/
- Type: url
The base URL of the npm package registry.
看到这个默认地址了吧,就是从这来的。这个就是官方地址:The official public npm registry is at http://registry.npmjs.org/, It is powered by a CouchDB database at http://isaacs.iriscouch.com/registry.
基本上了解了。
在看一下安装到哪,cmd输入 npm help npm 查看npm文档,有这段描述:
See folders(1) to learn about where npm puts stuff.
In particular, npm has two modes of operation:
- global mode:
npm installs packages into the install prefix atprefix/lib/node_modulesand bins are installed inprefix/bin. - local mode:
npm installs packages into the current project directory, which defaults to the current working directory. Packages are installed to./node_modules, and bins are installed to./node_modules/.bin.
Local mode is the default. Use --global or -g on any command to operate in global mode instead.
./node_modules of the current package root.-g): puts stuff in /usr/local or wherever node is installed.require() it.npm link我们通常使用require(),所以通常使用本地安装不使用全局安装。
文档下方还有 prefix Configuration 、Node Modules 、Executables 三段介绍,看过以后可以有更具体的了解,我就不多说了。
看express官方文档,可以证实:
Installation
$ npm install express
or to access the express(1) executable install globally:
$ npm install -g express到哪去找我需要的模块,有个网站必须提一下,http://search.npmjs.org/,这个就有点像maven的 http://mvnrepository.com/。
最近在研究以下几个第三方模块,分别介绍以下:
1. 上传文件:node-formidable 官网 https://github.com/felixge/node-formidable,官网下方有相关介绍和API
2.http中间件:connect(extjs同一家做了) 提供一个类似Javaee过滤器的框架,提供了很多中间件,如:日志、静态文件服务器,seesion等功能,官网 https://github.com/senchalabs/connect/ ,使用或看源码推荐看 https://github.com/senchalabs/connect/tree/1.8.2,因为默认首页是2.0版,代码已经重写了,帮助文档 http://senchalabs.github.com/connect/,它内部上传文件功能使用的就是formidable
3.web框架:express 提供了一个类似struts的框架,官网 http://expressjs.com/,文档 http://expressjs.com/guide.html,源码 https://github.com/visionmedia/express/,它是基于connect的。
4.web socket:Socket.IO 官网 http://socket.io/,源码https://github.com/learnboost/socket.io/
5.mongodb:node.js访问mongodb,官网https://github.com/christkv/node-mongodb-native
先来formidable做个安装试验:
cmd切换到工作目录,我的是D:\WebSite,
输入npm list

说明该目录没有安装任何东西
在该工作目录下建名为upload.js的文件,内容如下:
- var formidable = require('formidable');

运行报错。
开始安装输入npm install formidable,要等一会

安装成功。该目录下会生成node_modules文件夹。
现在可以使用了,再输入 node upload.js

不报错了,证明安装成功可以使用。关于上传代码的实现。参考 http://www.linuxidc.com/Linux/2012-02/53532.htm 与 http://www.linuxidc.com/Linux/2012-02/53530.htm
