I tried with a different solution to connect to the socket.io but I am not able to connect to it following is my code snippet.
app.js
var express = require('express'); var index = require('./routes/index'); var users = require('./routes/users'); var app = express(); // view engine setup app.set('views', path.join(__dirname, 'views')); app.set('view engine', 'jade'); app.use('/', index); app.use('/users', users); var http = require('http').Server(app); var io = require('socket.io')(http); io.on('connection', function(socket) { console.log('Client connected.'); }); http.listen(3000, function(){ console.log('listening on *:3000'); });
index.jade
extends layout
script(src='/socket.io/socket.io.js')
script.
var socket = io();
Package.json after installing socket.io
"socket.io": "^2.0.3"
Please suggest me where I am doing wrong
尝试使用新的关键字,可能会起作用
var app = new express();
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.