简体   繁体   中英

How to run Socket.io Chat Demo? Error on ..//

Hello I am new to programming and was trying to run the socket.io chat demo. However, when I try running it it gives me a error which is found at line 5 saying it can't find ('../..'). Can someone explain to me why this is happening?

Heres a snippet of the code where the issue is at:

 // Setup basic express server var express = require('express'); var app = express(); var server = require('http').createServer(app); var io = require('../..')(server); var port = process.env.PORT || 3000; server.listen(port, function () { console.log('Server listening at port %d', port); }); // Routing app.use(express.static(__dirname + '/public')); // Chatroom 

The source code of the full thing is on Github

The problem is with this line. In the example they have on github it works, because it links to the socket.io library which is in the root folder.

var io = require('../..')(server);

In your case if you are trying to lauch just this example and not the whole socket.io folder you need to install socket.io library with npm .

npm install --save socket.io

After downloading the library you can require it directly:

var io = require('socket.io')(server);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM