Skip to content

Commit 99a1a71

Browse files
committed
implement socket to server side
1 parent c6b9a52 commit 99a1a71

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

api/index.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,21 @@
1-
// server file
1+
// server file
2+
import express from "express";
3+
import {Server} from "socket.io";
4+
import {createServer} from "http";
5+
6+
const app = express();
7+
const server = createServer(app);
8+
const io = new Server(server);
9+
const PORT = 8080;
10+
11+
app.get('/', (req, res)=>{
12+
console.log('running')
13+
})
14+
15+
io.on('connection', (socket)=>{
16+
console.log('user connected socket')
17+
})
18+
19+
app.listen(PORT, ()=>{
20+
console.log(`server running on ${PORT}`)
21+
})

api/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"version": "1.0.0",
44
"description": "",
55
"main": "index.js",
6+
"type": "module",
67
"scripts": {
78
"test": "echo \"Error: no test specified\" && exit 1",
89
"server": "nodemon index.js"

0 commit comments

Comments
 (0)