Skip to content

Commit

Permalink
step 3: connect socket.io to express server
Browse files Browse the repository at this point in the history
  • Loading branch information
kchia committed Jun 24, 2020
1 parent cac665f commit de807c2
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/index.js
@@ -1,12 +1,20 @@
const express = require('express');
const http = require('http');
const path = require('path');
const socketio = require('socket.io');

const app = express();
const server = http.createServer(app);
const io = socketio(server);

const publicDirectoryPath = path.join(__dirname, '../public');
app.use(express.static(publicDirectoryPath));

io.on('connection', () => {
console.log('A new player just connected');
});

const port = process.env.PORT || 8080;
app.listen(port, () => {
server.listen(port, () => {
console.log(`Server is up on port ${port}.`);
});

0 comments on commit de807c2

Please sign in to comment.