错误很简单,应该就是说端口重了,访问http://127.0.0.1:8080/debug?port=5858 控制台信息: Error: read ECONNRESET Check there is no other debugger client attached to port 5858.
查了论坛和网上的帖子,关于inspector好像没说这个错,我找了好一会不知道哪里有问题,之前还用inspector来着,今天不知道怎么就报错了
代码如下:
(function (exports, require, module, __filename, __dirname) { var http = require(‘http’); var url = require(‘url’); var fs = require(‘fs’);
http.createServer(function(req,res){ //截取请求的url,端口后后面的部分 var pathname = url.parse(req.url).pathname; var realpath = "public"+pathname;
fs.exists(realpath,function(exists){ console.log(exists); if(!exists){ res.writeHead(404,{’Content-Type’:’text/plain’}); res.write(“404 not found!”); res.end(); }else{ fs.readFile(realpath,’utf-8’,function(err,data){ if(!err){ console.log(data); res.writeHead(200,{’Content-Type’:’text/html’}); res.write(data,’utf-8’); res.end(); }else{ res.writeHead(500,{’Content-Type’:’text/plain’}); res.end(err); } }); } }); //res.write(pathname); //res.writeHead(200,{’Content-Type’:’text/plain’}); //res.end(); }).listen(8888) });
就是一个静态文件服务器的demo,首先node-inpector,然后新开一个cmd,node --debug app.js,这两个顺序反过来也没用,明白的请指教~