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

2
w11_node/save-dots/server/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
node_modules/**
.vscode/**

View File

@@ -0,0 +1 @@
[]

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 () {
///...
});
});

1152
w11_node/save-dots/server/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,18 @@
{
"name": "save-dots-example",
"version": "1.0.0",
"description": "",
"main": "index.js",
"type": "module",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^5.1.0",
"socket.io": "^4.8.1"
}
}