Showing
3 changed files
with
14 additions
and
7 deletions
1 | import express from 'express'; | 1 | import express from 'express'; |
2 | +import socketIo from 'socket.io'; | ||
3 | +import { createServer } from 'http'; | ||
4 | + | ||
5 | +const PORT = 3000; | ||
2 | 6 | ||
3 | const app = express(); | 7 | const app = express(); |
4 | -const PORT = 8008; | 8 | +const server = createServer(app); |
9 | +const io = new socketIo.Server(server); | ||
5 | 10 | ||
6 | -app.get('/', (req, res) => res.send('Express + TypeScript Server')); | 11 | +io.on('connection', socket => { |
12 | + console.log('Connected.'); | ||
13 | +}) | ||
7 | 14 | ||
8 | -app.listen(PORT, () => { | 15 | +server.listen(PORT, () => console.log(`Listening on ${PORT}`)) |
9 | - console.log(`⚡️[server]: Server is running at http://localhost:${PORT}`); | ||
10 | -}); | ... | ... |
... | @@ -2,10 +2,12 @@ | ... | @@ -2,10 +2,12 @@ |
2 | "dependencies": { | 2 | "dependencies": { |
3 | "@types/express": "^4.17.11", | 3 | "@types/express": "^4.17.11", |
4 | "@types/node": "^15.3.1", | 4 | "@types/node": "^15.3.1", |
5 | + "@types/socket.io": "^3.0.2", | ||
6 | + "express": "^4.17.1", | ||
5 | "nodemon": "^2.0.7", | 7 | "nodemon": "^2.0.7", |
8 | + "socket.io": "^4.1.2", | ||
6 | "ts-node": "^9.1.1", | 9 | "ts-node": "^9.1.1", |
7 | - "typescript": "^4.2.4", | 10 | + "typescript": "^4.2.4" |
8 | - "express": "^4.17.1" | ||
9 | }, | 11 | }, |
10 | "scripts": { | 12 | "scripts": { |
11 | "start": "nodemon index.ts" | 13 | "start": "nodemon index.ts" | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment