nodejs module.js:340 throw err;使用WebSocket-Node

时间:2013-02-11 06:50:26

标签: node.js module runtime-error

我是新手,我在windows中安装了带有安装程序的nodejs。 然后我用这个命令安装了WebSocket-Node模块: npm install websocket,看起来像是成功安装。

npm http GET https://registry.npmjs.org/websocket
npm http 200 https://registry.npmjs.org/websocket
npm http GET https://registry.npmjs.org/websocket/-/websocket-1.0.8.tgz
npm http 200 https://registry.npmjs.org/websocket/-/websocket-1.0.8.tgz

> websocket@1.0.8 install D:\dev\html5\books\bumper\node_modules\websocket
> node install.js

[websocket v1.0.8] Attempting to compile native extensions.
[websocket v1.0.8] Native extension compilation successful!
websocket@1.0.8 node_modules\websocket

它在这个位置安装了nodejs:

  

c:\ Program Files(x86)\ nodejs \

现在我尝试从https://github.com/Worlize/WebSocket-Node执行server.js示例 我得到这个错误:

D:\dev\html5\books\bumper>node server.js

module.js:340
    throw err;
          ^
Error: Cannot find module '/path/to/websocket'
    at Function.Module._resolveFilename (module.js:338:15)
    at Function.Module._load (module.js:280:25)
    at Module.require (module.js:362:17)
    at require (module.js:378:17)
    at Object.<anonymous> (D:\dev\html5\books\bumper\server.js:3:23)
    at Module._compile (module.js:449:26)
    at Object.Module._extensions..js (module.js:467:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.runMain (module.js:492:10)

也是模块安装在项目根目录中没有在nodejs目录下,是否可以?

1 个答案:

答案 0 :(得分:1)

根据错误消息,看起来需求行看起来像这样

var websocket = require('/path/to/websocket');

使用npm安装后,您只能使用模块名称:

var websocket = require('websocket');
相关问题