欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

express-common篇

程序员文章站 2022-03-22 10:05:31
const os = require("os");const interfaces = require('os').networkInterfaces();const fs = require('fs');const path = require('path');module.exports.GetIpaddr = function(){var ipaddrs = [];for(var devName in interfaces){var iface = interfaces[dev...
const os = require("os");
const interfaces = require('os').networkInterfaces();
const fs = require('fs');
const path = require('path');

module.exports.GetIpaddr = function(){
	var ipaddrs = [];
	for(var devName in interfaces){
		var iface = interfaces[devName];
		for(var i=0;i<iface.length;i++){
			var alias = iface[i];
			if(alias.family === 'IPv4' && alias.address !== '127.0.0.1' && !alias.internal){
				ipaddrs.push(alias.address);
			}
		}
	}
	return ipaddrs[0];
};

module.exports.OsType = function(){
    return os.type();
};

module.exports.IsLinux = function(){
	if(os.type()=="Linux"){
		return true;
	}else{
		return false;
	}
};


module.exports.getSmsCode = function(){
    var Num="";
  	 for(var i=0;i<6;i++) {
        Num+=Math.floor(Math.random()*10);
    }
    return Num;
};

module.exports.mkdirsSync = function(dirname) {
	 if (fs.existsSync(dirname)) {
	 	return true;
	 } else {
	 	if (this.mkdirsSync(path.dirname(dirname))) {
	 		fs.mkdirSync(dirname);
	 		 return true;
	 		 }
    }
};

app.js

logger.info('Local ip address is  ' + comm.GetIpaddr());

本文地址:https://blog.csdn.net/qq_38504352/article/details/107387520