mirror of
https://github.com/sergeyyarkov/react-chat-app.git
synced 2026-10-11 10:29:04 +03:00
19 lines
443 B
JavaScript
19 lines
443 B
JavaScript
const server = require('express')()
|
|
const http = require('http').createServer(server)
|
|
const io = require('socket.io')(http)
|
|
|
|
const PORT = process.env.PORT || 3001
|
|
|
|
server.get('/', (req, res) => {
|
|
res.send('Chat API')
|
|
})
|
|
|
|
io.on('connection', (socket) => {
|
|
socket.on('chat:message', (message, username) => {
|
|
io.emit('chat:message', message, username)
|
|
})
|
|
})
|
|
|
|
http.listen(PORT, () => {
|
|
console.log(`Server running on port: ${PORT}`)
|
|
}) |