码迷,mamicode.com
首页 > 其他好文 > 详细

node基础03:使用函数

时间:2017-01-03 09:51:22      阅读:146      评论:0      收藏:0      [点我收藏+]

标签:tput   情况   put   char   running   world   console   name   pre   

1.使用函数

//server.js

var http = require("http");
var output = require("./output");

http.createServer(function(request, response){
    response.writeHead(200, {"Content-Type":"text/html; charset=uf-8"});
    if (request.url!=="/favicon.ico") {
        console.log(output);
        output(request, response);
    }
}).listen(8000);
console.log(‘Server running at http://127.0.0.1:8000/‘);
//output.js
function output(request, response){
    response.write(‘hello world‘);
    console.log(‘hello‘);
    response.end();
}

module.exports = output//只支持一个函数,通常情况下导出的为一个对象

/**
 module.exports = {
    fn1: fn1,
    fn2: fn2
 }

 在其他模块调用时,使用 别名.fnName()调用这里的fn1
 **/

node基础03:使用函数

标签:tput   情况   put   char   running   world   console   name   pre   

原文地址:http://www.cnblogs.com/noper/p/6243724.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!