Posted in NodeJs onMarch 27, 2017
server.js
var http = require("http"); var url = require("url"); function start(route){//route.js 的route方法 //服务实现 function onRequest(request,response){ var pathname = url.parse(request.url.).pathname; route(pathname); // response.writeHead(200,{"Content-Type":"text/plain"}); response.write("只是一个练手罢了"); response.end(); } //创建服务 http.createServer(onRequest).listen(8888);//端口号8888 console.log("服务启动");//后台输出,表示服务启动成功 } exports.start = start; //将start方法暴露出去
========================================
route.js
function route(pathname){ console.log("请求路径是:" + pathname); //后台查看请求路劲 区分请求的地址 } exports.route = route;
========================================
index.js
var server = require("./server"); var router = require("./route"); server.start(router.route);//传递?start的是router的route方法
nodejs学习笔记之路由
- Author -
成功需要积累声明:登载此文出于传递更多信息之目的,并不意味着赞同其观点或证实其描述。
Reply on: @reply_date@
@reply_contents@