//主程序
var http = require("http");
var otherfun = require("./models/otherfuns.js"); //导入外部模块
http.createServer(function (request, response) {
response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'}); //协议头
if(request.url !== "/favicon.ico") { //清除第二次访问
fun1(response); //调用内部函数
otherfun.fun2(response); //调用外部函数
otherfun.fun3(response);
response.end(""); //协议尾
}
}).listen(8000);
console.log("Server running at http://127.0.0.1:8000/");
function fun1(res) {
console.log("fun1");
res.write("hello,我是fun1");
}
//外部模块
module.exports = {
fun2: function (res) {
console.log("fun2");
res.write("hello,我是fun2");
},
fun3: function (res) {
console.log("fun3");
res.write("hello,我是fun3");
}
};
函数调用
最后编辑于 :
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 我们在写类的构造函数的时候, 有时候一个构造函数可以完成另一个构造函数中的一部分内容, 这时候我们就希望调用另一...