blob: 4a5a89e7620aeba655f35aa23b537c6179665697 (
plain)
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
|
#!/usr/bin/env node
import fs from 'fs/promises';
import { WebSocketServer } from 'ws';
const wss = new WebSocketServer({ port: 59497 });
const timestamp = new Date().toISOString().slice(0, 19).replace(/[:]/g, '-')
const filename = `wslog-${timestamp}.txt`
const f = await fs.open(filename, 'w');
console.log(`Writing to ${filename}`);
console.log('Ctrl-C to stop');
process.on('SIGINT', () => {
console.log(`\nWritten to ${filename}`);
process.exit();
});
wss.on('connection', async ws => {
ws.on('message', data => {
const s = data.toString();
f.write(s + '\n');
console.log(s);
});
});
|