nodejs路由信息
Posted 月疯
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了nodejs路由信息相关的知识,希望对你有一定的参考价值。
var pathname=url.parse(request.url).pathname;
//导入http
var http=require('http');
var url=require('url');
var router = require('../module/router.js');
//创建
http.createServer(function (request,response) {
response.writeHead(200,{'Content-type':'text/html;charset=utf-8'});
if(request.url!=='/favicon.ico'){//清除二次访问
var pathname=url.parse(request.url).pathname;
pathname=pathname.replace(/\\//,'');//替换前面/
console.log(pathname)
router[pathname](request,response);
response.end("");//不写会没有协议尾部,但是写了会访问俩次
}
}).listen(8081);
console.log('Server running at http://127.0.0.11:8081/')
module/router.js
module.exports={
login:function(req,res){
res.write('我是login方法');
},
zhuce:function(req,res){
res.write('我是注册');
},
}
以上是关于nodejs路由信息的主要内容,如果未能解决你的问题,请参考以下文章
使用 NodeJS 和 JSDOM/jQuery 从代码片段构建 PHP 页面