小弟初学node.js写了几个文件
第一个是入口文件index.js
var http = require('./server'); var rouser = require('./rouse'); var head = {}; head['/']=rouser.start; head['/start']=rouser.start; head['/upload']=rouser.upload; http.server(rouser.rouse,head); 第二个文件 server.js
var http = require('http'); var url = require('url');
function server(rouse,head){ function ser(req,res){ var urls = url.parse(req.url).pathname; var aa = rouse(urls,head); res.write(aa); //res.write(req.url); res.end(); } http.createServer(ser).listen('3000'); }
exports.server=server; 第三个文件 rouse.js文件
function rouse(urls,head){ return headurls; } function upload(){ return "Hello upload"; } function start(){ return "Hello Start"; } exports.rouse = rouse; exports.start = start; exports.upload = upload; 这几个文件 我用cmd运行index.js 运行第一次正常 在运行一次就无法找到了 求高手告知怎么回事 小弟在此谢过