-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
39 lines (31 loc) · 938 Bytes
/
server.js
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
31
32
33
34
35
36
37
38
39
import { createServer } from 'node:http';
import { parseArgs, styleText } from 'node:util';
import { glob, watch } from 'node:fs/promises';
import { createReadStream } from 'node:fs';
const options = {
hi: {
type: 'string',
short: 'f',
},
bar: {
type: 'string',
},
};
const { values, positionals } = parseArgs({ args: process.args, options });
console.log(values, positionals);
console.log(styleText(['green', 'underline'], values.hi));
// for await (const file of glob(`${import.meta.dirname}/*`)) {
for await (const file of watch(`${import.meta.dirname}`)) {
if (file.filename.endsWith('js')) {
const stream = createReadStream(file.filename);
for await (const chunk of stream) {
console.log(styleText('green', chunk.toString().toUpperCase()));
}
}
}
// const server = createServer();
// server.on('request', (_req, res) => {
// console.log('hello');
// res.end('response');
// });
// server.listen(3000);