Code was correctly but show Error on node js socket io ?
....................................................................................................................
app.js
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
app.get('/', function(req,res){
res.sendfile('index.html');
});
var clients = 0;
io.on('connect', function(socket){
clients++;
io.sockets.emit('boardcast', {message: clients + ' clients connected!'});
//console.log(io.sockets)
socket.on('disconnect', function(){
clients--;
io.sockets.emit('boardcast', {message: clients + ' clients connected!'});
});
});
http.listen(3000, function(){
console.log('start server on port :3000');
});
index.html
<html>
<head></head>
<body>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.0.4/socket.io.js"></script>
<script type="text/javascript">
var socket = io();
socket.on('boardcast', function(data){
document.body.innerHTML = '';
document.write(data.message);
});
</script>
<h1>hello world</h1>
</body>
</html>
.
ssh
node app.js
return value
start server on port :3000
express deprecated res.sendfile: Use res.sendFile instead app.js:6:6
sendFilenotsendfileres.sendFile('index.html');-------- It's show error -----------TypeError: path must be absolute or specify root to res.sendFile at ServerResponse.sendFile (/home/admin/web/my-domain.com/public_html/node_modules/express/lib/response.js:421:11) at /home/admin/web/my-domain.com/public_html/app.js:6:6 at Layer.handle [as handle_request] (/home/admin/web/my-domain.com/public_html/node_modules/express/lib/router/layer.js:95:5) at next (/home/admin/web/my-domain.com/public_html/node_modules/express/lib/router/route.js:137:13) at Route.dispatch (/home/admin/web/my-domain.com/public_html/node_modules/express/lib/router/route.js:112:3)