opn和网络提示

ⅰ亾dé卋堺 提交于 2020-01-22 16:11:40

server.js:

const Koa = require('koa');
const config = require('./config');
const opn = require('opn');
const network = require('./libs/network');

let server = new Koa();

(async ()=>{
    server.context.db = await require('./libs/mysql')
    server.context.redis = require('./libs/redis')

    server.listen(config.port)

    network.forEach(ip =>{
        if(config.port == 80) {
            console.log(`server running at ${ip}`);
        }else{
            console.log(`server running at ${ip}:${config.port}`);
        }
    })
    

    opn(`http://localhost:${config.port}`)
})();

network.js:

const os = require('os');

let arr = [];
let json = os.networkInterfaces();
    for(let name in json) {
        if(name.startsWith('VMware'))continue;
        json[name].forEach(item=>{
            if(item.family=='IPv4') {
                arr.push(item.address)
            }
        })
    }

module.exports = arr;

在这里插入图片描述

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!