-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
28 lines (22 loc) · 715 Bytes
/
app.js
File metadata and controls
28 lines (22 loc) · 715 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
/* jshint esversion: 6 */
const express = require('express');
const app = express();
const http = require('http').createServer(app);
const io = require('socket.io')(http);
let hostname = '127.0.0.1';
let port = 3000;
app.use(express.static(__dirname));
app.get('/', function(req, res){
res.sendFile(__dirname + '/index.html');
});
io.on('connection', function(socket){
console.log('a user connected');
socket.on('something', () => {
console.log('something');
let data = "hello world";
socket.emit('somethingElse', data);
});
});
http.listen(process.env.PORT || 3000, function(){
console.log('Server running at http://${hostname}:${port}/', hostname, port);
});