node第一个程序
var http = require('http') var url = require('url') var fs=require("fs") var router = require('./router.js'); http.createServer(function(req, res){ // res.writeHead(200, {'Content_Type': 'text/html; charset=utf-8'}) if(req.url !== '/favicon.ico') { res.setHeader("Access-Control-Allow-Origin", "*");//设置访问代理。 var pathName = url.parse(req.url).pathname.replace(/\//, '') try { router[pathName](req, res); } catch(err) { router['home'](req, res); } } }).listen(8000) console.log('Server running at http://localhost:8000')