Last active
April 8, 2020 16:02
-
-
Save maxgfr/0247555ca90a44b355bbebe89bcb5c92 to your computer and use it in GitHub Desktop.
Socket.io + Express JS + React JS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var socket = require('socket.io'); | |
var express = require('express'); | |
var app = express(); | |
var path = require('path'); | |
app.use(express.static(path.join(__dirname, 'build'))); | |
app.get('/*', function(req, res) { | |
res.sendFile(path.join(__dirname, 'build', 'index.html')); | |
}); | |
const server = app.listen(process.env.PORT || '80', () => console.log(`App is listening on port ${process.env.PORT || '80'}!`)); | |
const io = socket(server); | |
io.on('connection', (socket) => { | |
socket.on('send_event_to_front', (data) => { | |
io.emit('new_message', data); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment