-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdev-with-qr.js
More file actions
36 lines (30 loc) · 1.07 KB
/
dev-with-qr.js
File metadata and controls
36 lines (30 loc) · 1.07 KB
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
// This configuration is used to expose QR code in the terminal, you need to set up in package.json as follows: "dev": "pnpm lint && node dev-with-qr.js",
const { exec } = require('child_process');
const qrcode = require('qrcode-terminal');
const os = require('os');
function getLocalIp() {
const interfaces = os.networkInterfaces();
for (const name of Object.keys(interfaces)) {
for (const iface of interfaces[name]) {
if (iface.family === 'IPv4' && !iface.internal) {
return iface.address;
}
}
}
}
const ip = getLocalIp();
const port = 5000;
const url = `http://${ip}:${port}`;
const devProcess = exec(`next dev --turbopack -p ${port} -H 0.0.0.0`, (err) => {
if (err) {
console.error('Error starting Next.js:', err);
}
});
// Display QR code in terminal
qrcode.generate(url, { small: true }, (qr) => {
console.log(`App running at ${url}`);
console.log('Scan QR code to access:');
console.log(qr);
});
devProcess.stdout.on('data', (data) => console.log(data.toString()));
devProcess.stderr.on('data', (data) => console.error(data.toString()));