-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
28 lines (23 loc) · 845 Bytes
/
server.js
File metadata and controls
28 lines (23 loc) · 845 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
// Socket server implementation only for now. User configuration with MongoDB pending.
// Refer to "server" folder for MongoDB configuration
// Import express and instantiate an express server called "app"
const express = require("express")
const app = express()
// Middleware
const cors = require('cors');
app.use(cors());
const server = app.listen(8000, () =>
console.log("The server is all fired up on port 8000")
)
// To initialize the socket, we need to
// invoke the socket.io library
// and pass it our Express server
const io = require("socket.io")(server, { cors: true })
io.on("connection", (socket) => {
console.log("New connection -->", socket.id)
socket.emit("welcome", "Welcome to the socket!")
socket.on("chat_message", (msg) => {
console.log("message: " + msg.content)
io.emit("server_message", msg)
})
})