node exercise
This commit is contained in:
34
w11_node/save-dots/server/index.js
Normal file
34
w11_node/save-dots/server/index.js
Normal 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 () {
|
||||
///...
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user