![](/img/trans.png)
[英]Node.JS scalable (using Node.JS-cluster) socket-server with Engine.IO, pairing/syncing (also called second screen) two devices, on same worker…
[英]issues while installing engine.io node js
我正在尝试安装engine.io
( https://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>节点“c:\\ users \\ user \\ documents \\ visual studio 2010 \\ Projec ts \\ nodes \\ WebApplication1 \\ NodeFiles \\ engineTest.js”
module.js:338
扔错了;
^
错误:找不到模块'engine.io'
在Function.Module._resolveFilename(module.js:336:15)
在Function.Module._load(module.js:278:25)
在Module.require(module.js:365:17)
at require(module.js:384:17)
在对象。 (c:\\ users \\ user \\ documents \\ visual studio 2010 \\ Proje cts \\ 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>
我想我做的事情很傻。
有人可以帮帮我吗?
您已在目录C:\\Windows\\system32
下安装了engine.io
模块。 这意味着你有一个node_modules
文件夹中systems32
,而不是在你的项目文件夹。 这不是你想要的。
我建议你从头开始:
打开cmd并执行以下命令
mkdir testproject
cd testproject
engine.io
:
npm install engine.io
node_modules
的文件夹 app.js
app.js
node app.js
您的应用现在应该可以工作
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.