-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMicro.js
More file actions
30 lines (26 loc) · 722 Bytes
/
Micro.js
File metadata and controls
30 lines (26 loc) · 722 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
29
30
const express = require('express');
const app = express();
const server = require('http').createServer(app);
const io = require('socket.io')(server);
app.get('/', (req, res) => {
res.send(`
<html>
<body>
<form method="POST" action="/send-message">
<button type="submit">Send Message</button>
</form>
</body>
</html>
`);
});
app.post('/send-message', (req, res) => {
// Send the message to all connected clients using Socket.IO
io.emit('message', 'This is a message from the server');
res.redirect('/');
});
io.on('connection', (socket) => {
console.log('A client connected');
});
server.listen(3000, () => {
console.log('Server listening on port 3000');
});