1.基础实例
//server.js var http = require("http"); var url = require("url"); var router = require("./router"); http.createServer(function(req, res){ res.writeHead(200, {'Content-Type':'text/html;charset=utf-8'}); if(req.url!=="/favicon.ico"){ var pathname = url.parse(req.url).pathname; pathname = pathname.replace(///,''); console.log(pathname); router[pathname](req,res); res.end(); } }).listen(8000); console.log('Server running at http://127.0.0.1:8000/');
//router.js module.exports = { login:function(req, res){ res.write("login"); }, register:function(request, response){ res.write("register"); } }