I am trying to install engine.io
(https://www.npmjs.com/package/engine.io)
I am getting the following error:
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)
After this I try to execute this js script
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
});
I get this error
C:\Windows\system32>node "c:\users\user\documents\visual studio 2010\Projec ts\nodes\WebApplication1\NodeFiles\engineTest.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. (c:\users\user\documents\visual studio 2010\Proje cts\node\WebApplication1\NodeFiles\engineTest.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)
--------------------------------------------------------------------------
Actually I think I am not doing something right. Let me explain
First of all i think the installation of engine.io
is correct as all of you are suggesting.
Now when I try running the command "var engine = require('engine.io');"
from the node console, it works perfectly and the engine variable is instantiated with the data.
When I check engine it shows me.
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] }
>
But when I write that line in a JS file and then try and run it with the node command it breaks.Error
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>
I think I am doing something silly.
Could someone please help me out?
You have installed the engine.io
module under the directory C:\Windows\system32
. This means that you have a node_modules
folder in systems32
, not in your project folder. This is not what you want.
I would recommend you start from scratch:
Open the cmd and do the following commands
mkdir testproject
cd testproject
engine.io
:
npm install engine.io
node_modules
in your project folderapp.js
in the project folder with your content.app.js
node app.js
Your app should now work.