0

我正在尝试安装engine.iohttps://www.npmjs.com/package/engine.io

我收到以下错误

C:\Windows\system32>npm install engine.io

ws@0.5.0 install C:\Windows\system32\node_modules\engine.io\node_modules\ws
(node-gyp rebuild 2> builderror.log) || (exit 0)


C:\Windows\system32\node_modules\engine.io\node_modules\ws>node "C:\Program File
s (x86)\nodejs\node_modules\npm\bin\node-gyp-bin\\..\..\node_modules\node-gyp\bi
n\node-gyp.js" rebuild
engine.io@1.5.1 node_modules\engine.io
├── base64id@0.1.0
├── debug@1.0.3 (ms@0.6.2)
├── engine.io-parser@1.2.1 (blob@0.0.2, arraybuffer.slice@0.0.6, after@0.8.1, ba
se64-arraybuffer@0.1.2, utf8@2.0.0, has-binary@0.1.5)
└── ws@0.5.0 (options@0.0.6, ultron@1.0.1, nan@1.4.3)

在此之后我尝试执行这个 js 脚本

var engine = require('engine.io');
var server = engine.listen(80);

server.on('connection', function(socket){
  socket.send('utf 8 string');
  socket.send(new Buffer([0, 1, 2, 3, 4, 5])); // binary data
});

我收到这个错误

C:\Windows\system32>node "c:\users\user\documents\visual studio 2010\Projec ts\nodes\WebApplication1\NodeFiles\engineTest.js"
module.js:338
throw err;
^
错误:

Function.Module._load (module.js:278:25)
在 Module.require (module.js: 365:17)在对象
的要求(module.js:384:17)
。(c:\users\user\documents\visual studio 2010\Projects\node\WebApplication1\NodeFiles\engineTest.js:1:76)
在 Module._compile (module.js:460:26)
在 Object.Module._extensions ..js (module.js:478:10)
在 Module.load (module.js:355:32)
在 Function.Module._load (module.js:310:12)
在 Function.Module.runMain (module.js:501:10)

-------------------------------------------------- ----------------------

其实我觉得我做的不对。让我解释

首先,我认为engine.io正如你们所有人所建议的那样,安装是正确的。

现在,当我尝试"var engine = require('engine.io');"从节点控制台运行命令时,它可以完美运行,并且引擎变量已用数据实例化。


当我检查引擎时,它显示给我。

C:\Users\Ankur>node
> var engine = require('engine.io');
undefined
> engine
{ [Function]
  protocol: 1,
  Server:
   { [Function: Server]
     errors:
      { UNKNOWN_TRANSPORT: 0,
        UNKNOWN_SID: 1,
        BAD_HANDSHAKE_METHOD: 2,
        BAD_REQUEST: 3 },
     errorMessages:
      { '0': 'Transport unknown',
        '1': 'Session ID unknown',
        '2': 'Bad handshake method',
        '3': 'Bad request' } },
  Socket: [Function: Socket],
  Transport: [Function: Transport],
  transports:
   { polling: { [Function: polling] upgradesTo: [Object] },
     websocket: [Function: WebSocket] },
  parser:
   { protocol: 3,
     packets:
      { open: 0,
        close: 1,
        ping: 2,
        pong: 3,
        message: 4,
        upgrade: 5,
        noop: 6 },
     encodePacket: [Function],
     encodeBase64Packet: [Function],
     decodePacket: [Function],
     decodeBase64Packet: [Function],
     encodePayload: [Function],
     decodePayload: [Function],
     encodePayloadAsBinary: [Function],
     decodePayloadAsBinary: [Function] },
  listen: [Function: listen],
  attach: [Function: attach] }
>

但是,当我在 JS 文件中写入该行,然后尝试使用 node 命令运行它时,它会中断。错误

C:\Users\Ankur>node "e:\engine.js"
module.js:338
    throw err;
          ^
Error: Cannot find module 'engine.io'
    at Function.Module._resolveFilename (module.js:336:15)
    at Function.Module._load (module.js:278:25)
    at Module.require (module.js:365:17)
    at require (module.js:384:17)
    at Object.<anonymous> (e:\engine.js:1:76)
    at Module._compile (module.js:460:26)
    at Object.Module._extensions..js (module.js:478:10)
    at Module.load (module.js:355:32)
    at Function.Module._load (module.js:310:12)
    at Function.Module.runMain (module.js:501:10)

C:\Users\Ankur>

我想我在做一些愚蠢的事情。

有人可以帮我吗?

4

1 回答 1

0

您已经在目录下安装了engine.io模块C:\Windows\system32。这意味着您有一个node_modules文件夹systems32,而不是在您的项目文件夹中。这不是你想要的。

我建议你从头开始:

打开cmd并执行以下命令

  1. 为您的项目创建一个文件夹:
    • mkdir testproject
  2. 导航到文本项目文件夹:
    • cd testproject
  3. 安装您需要的模块,即engine.io
    • npm install engine.io
  4. node_modules现在您的项目文件夹中应该有一个名为的文件夹
  5. app.js使用您的内容在项目文件夹中创建文件。
  6. app.js
    • node app.js

您的应用程序现在应该可以工作了。

于 2015-02-28T11:19:00.997 回答