-
Notifications
You must be signed in to change notification settings - Fork 0
/
start.js
35 lines (29 loc) · 1.13 KB
/
start.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
const express = require('express');
const serveStatic = require('serve-static');
const livereload = require("livereload");
const connectLiveReload = require("connect-livereload");
const os = require('node:os');
const QRCode = require('qrcode')
const PORT = 7007;
const liveReloadServer = livereload.createServer();
liveReloadServer.server.once("connection", () => {
setTimeout(() => {
liveReloadServer.refresh("/");
}, 100);
});
const app = express();
app.use(connectLiveReload());
app.use(serveStatic(__dirname));
var networkInterfaces = os.networkInterfaces();
const ipAddressList = Object.values(networkInterfaces)
.flat()
.filter(({ family, internal }) => family === "IPv4" && !internal)
.map(({ address }) => address)
const ipAddress = ipAddressList[ipAddressList.length - 1];
let server = app.listen(PORT, '0.0.0.0', () => {
console.log('\x1b[36m%s\x1b[0m', `Server is running on http://localhost:${PORT}`);
console.log('\x1b[36m%s\x1b[0m', `Server is running on http://${ipAddress}:${PORT}`);
QRCode.toString(`http://${ipAddress}:${PORT}`, { small:true,type: 'terminal' }, function (err, url) {
console.log(url)
})
});