HTTP服务器中的自定义模块要如何获取PATH或者返回信息?
//index.js var http = require(“http”); var api = require(“api”); //这是我自定义的模块
http.createServer(function(request, response) { api.api(url.parse(request.url).pathname); //可以这样把pathname给api函数,但是如果不给它pathname,api函数要如何获取pathname api.api(); //简而言之就是如何实现这个模块让它可以这样直接输出pathname??? response.writeHead(200, {“Content-Type”: “text/plain”}); response.write(“Hello World”); response.end(); }).listen(8888);
//api.js function api(pathname) { console.log(pathname); } exports.api = api;