无法在windows 7上找到“connect”模块

时间:2021-08-01 09:33:44

Please see below:

请见下文:

    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>

Is my install of Connect module successful? How do I know 'Connect' is properly installed?

我的连接模块安装成功了吗?如何知道'Connect'已正确安装?

Also, when I try to start my server, I get the following error:

另外,当我尝试启动我的服务器时,我得到以下错误:

    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)

And the code in my server.js is as follows:

还有我服务器上的代码。js如下:

    var connect = require('connect');

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

).listen(5000);

Any ideas why I cannot connect? Thanks!

你知道我为什么不能联系吗?谢谢!

2 个解决方案

#1


1  

You can't require() modules that you've installed with the -g flag in npm. Remove the -g flag: npm install connect. The -g is for installing modules that provide command-line utilities, such as the express-generator module.

您不能要求在npm中安装了-g标志的()模块。移除-g标志:npm安装连接。g用于安装提供命令行实用程序的模块,如express-generator模块。

Also, you really shouldn't use C:\Program Files\nodejs for your project since npm will install modules in a subdirectory of your current working directory...

还有,你真的不应该用C:\Program Files\nodejs为您的项目因为npm将模块安装在你当前工作目录的子目录……

#2


0  

Try to verify whether Environment Variable for npm is set properly? [You can check by right clicking my Computer->properties->Advance System Settings tab.

尝试验证npm的环境变量是否设置正确?[你可以右键点击我的电脑->属性->系统预置设置选项卡来检查。

For example DriveLetter:\Users\UserName\AppData\Roaming\npm

例如DriveLetter:\ \用户名\ AppData \漫游用户\ npm

#1


1  

You can't require() modules that you've installed with the -g flag in npm. Remove the -g flag: npm install connect. The -g is for installing modules that provide command-line utilities, such as the express-generator module.

您不能要求在npm中安装了-g标志的()模块。移除-g标志:npm安装连接。g用于安装提供命令行实用程序的模块,如express-generator模块。

Also, you really shouldn't use C:\Program Files\nodejs for your project since npm will install modules in a subdirectory of your current working directory...

还有,你真的不应该用C:\Program Files\nodejs为您的项目因为npm将模块安装在你当前工作目录的子目录……

#2


0  

Try to verify whether Environment Variable for npm is set properly? [You can check by right clicking my Computer->properties->Advance System Settings tab.

尝试验证npm的环境变量是否设置正确?[你可以右键点击我的电脑->属性->系统预置设置选项卡来检查。

For example DriveLetter:\Users\UserName\AppData\Roaming\npm

例如DriveLetter:\ \用户名\ AppData \漫游用户\ npm