在Windows 7上找不到模块'connect'

时间:2014-09-03 14:43:26

标签: node.js npm connect windows-7-x64

请参阅以下内容:

    C:\Program Files\nodejs>npm -g install connect
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/connect
npm http GET https://registry.npmjs.org/finalhandler/0.1.0
npm http GET https://registry.npmjs.org/debug/1.0.4
npm http GET https://registry.npmjs.org/parseurl
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/finalhandler/0.1.0
npm http GET https://registry.npmjs.org/parseurl
npm http GET https://registry.npmjs.org/debug/1.0.4
npm http GET https://registry.npmjs.org/utils-merge/1.0.0
npm http GET https://registry.npmjs.org/parseurl
npm http GET https://registry.npmjs.org/debug/1.0.4
npm http GET https://registry.npmjs.org/finalhandler/0.1.0
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/ms/0.6.2
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/ms/0.6.2
npm http GET https://registry.npmjs.org/escape-html/1.0.1
npm http GET https://registry.npmjs.org/ms/0.6.2
connect@3.1.1 C:\Users\u166824\AppData\Roaming\npm\node_modules\connect
├── utils-merge@1.0.0
├── parseurl@1.3.0
├── debug@1.0.4 (ms@0.6.2)
└── finalhandler@0.1.0 (escape-html@1.0.1)

C:\Program Files\nodejs>

我的Connect模块安装成功了吗?我怎么知道' Connect'安装得好吗?

此外,当我尝试启动服务器时,出现以下错误:

    C:\Program Files\nodejs>node server.js

module.js:340
    throw err;
          ^
Error: Cannot find module 'connect'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (C:\Program Files\nodejs\server.js:1:77)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Function.Module.runMain (module.js:497:10)

我的server.js中的代码如下:

    var connect = require('connect');

connect.createServer(
    connect.static("../angularjs")

).listen(5000);

为什么我无法连接的任何想法?谢谢!

2 个答案:

答案 0 :(得分:1)

在npm中,您不能使用require()标志安装-g个模块。删除-g标记:npm install connect-g用于安装提供命令行实用程序的模块,例如express-generator模块。

另外,你真的不应该为你的项目使用C:\Program Files\nodejs,因为npm会将模块安装在你当前工作目录的子目录中......

答案 1 :(得分:0)

尝试验证npm的环境变量是否设置正确? [您可以通过右键单击我的计算机 - >属性 - &gt;高级系统设置选项卡进行检查。

例如DriveLetter:\ Users \ UserName \ AppData \ Roaming \ npm