Skip to content

Instantly share code, notes, and snippets.

@krnlde
Last active December 14, 2020 15:53
const qrcode = require('qrcode-terminal');
const open = require('open');
// setup your httpServer as you like (express.js)
// ...
// The '0.0.0.0' binding is important here, otherwise the addresses will not work
httpsServer.listen(1337, '0.0.0.0', () => {
for (const [_, addresses] of Object.entries(os.networkInterfaces())) {
const relevantAddresses = addresses.filter((a) => !a.internal && a.family === 'IPv4').map((a) => a.address);
if (!relevantAddresses.length) continue;
console.log(`\n`);
for (const address of relevantAddresses) {
console.log(`\n* Also listening on: https://${address}:1337\n`);
qrcode.generate(`https://${address}:1337`);
}
console.log(`\n`);
}
open('https://localhost:1337');
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment