nodo.js 模块化 交互模式
console.log('如何在nodejs环境中运行一个独立的js文件呢?');
const http = require('http');
http.createServer((req,res)=>{
res.end('hello');
}).listen(8000,()=>{
console.log('server ok');
})
let tools = {
randomInt : function(min,max){
return Math.floor(Math.random() * (max - min + 1) + min);
},
arrMax : function(arr){
return Math.max.apply(null,arr);
}
}
module.exports = tools;
exports.rand = tools.randomInt;
exports.max = tools.arrMax;
let tools = require('./mod_01');
console.log(tools.arrMax([24,3,2,21,45,6]))
console.log(tools.max([24,3,2,21,45,6]));
console.log(tools.rand(4,7));