node exercise

This commit is contained in:
Andrea Bianchi
2026-05-11 14:03:20 +09:00
parent 1cb979a571
commit f63f652f76
8 changed files with 1270 additions and 0 deletions

View File

@@ -0,0 +1,34 @@
import path from 'path';
import express from 'express';
import fs from 'fs';
import { createServer } from 'http';
import { Server } from 'socket.io';
// Create a server on port 3000
const PORT = process.env.PORT || 3000;
const app = express();
const server = createServer(app);
// socket.io
const io = new Server(server, {
cors: {
origin: '*',
},
});
server.listen(PORT, function () {
console.log('Server listening at port %d', PORT);
});
// Optionally routing your app
// app.use(express.static(path.join(__dirname, '../client')));
io.on('connection', function (socket) {
socket.on('save', function (data) {
//...
});
socket.on('load', function () {
///...
});
});