-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
executable file
·43 lines (34 loc) · 1.3 KB
/
index.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
40
41
42
43
#!/usr/bin/env node
const path = require('path');
const fs = require('fs');
const http = require('http');
const ngrok = require('ngrok');
const qrcode = require('qrcode-terminal');
const BOLD = '\033[1m';
const main = async () => {
if (process.argv.length < 3) return console.error('Missing file to serve: please provide one.');
const filePath = path.resolve(__dirname, process.argv[2]);
const url = await ngrok.connect(8080);
const server = http.createServer((req, res) => {
const stream = fs.createReadStream(filePath);
stream.pipe(res);
stream.on('end', async () => {
console.log('File served! Closing all the connections...');
server.close();
await ngrok.kill();
console.log('Connection closed, goodbye!');
});
}).listen(8080);
console.log(`
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Ready to serve >> ${BOLD}${filePath}
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
`);
qrcode.generate(url);
console.log(`
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Scan this QRCode to download the file or go to this link: ${BOLD}${url}
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
`);
};
main();