首页 > node.js模仿路由的问题

node.js模仿路由的问题

程序的代码是这样的,感觉挺简单。

var http = require('http');

http.createServer(function(request,response){
    if(request.url == "/a"){
        request.writeHead(200, {'Content-Type':'text/plain'});
        response.end('欢迎访问aaaa!');
    } else if(request.url == "/b"){
        request.writeHead(200, {'Content-Type':'text/plain'});
        response.end('欢迎访问bbbb!');
    } else {
        request.writeHead(404, {'Content-Type':'text/plain'});
        request.end('对不起,没有这个页面');
    }
}).listen(3000,'127.0.0.1');

但是却出现了以下的报错:

"D:\Program Files (x86)\JetBrains\WebStorm 10.0.4\bin\runnerw.exe" "D:\Program Files\nodejs\node.exe" d:\webstorm_workspace\Study\NodejsDemo\router_test.js
events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: listen EADDRINUSE 127.0.0.1:3000
    at Object.exports._errnoException (util.js:870:11)
    at exports._exceptionWithHostPort (util.js:893:20)
    at Server._listen2 (net.js:1234:14)
    at listen (net.js:1270:10)
    at net.js:1379:9
    at nextTickCallbackWith3Args (node.js:453:9)
    at process._tickCallback (node.js:359:17)
    at Function.Module.runMain (module.js:443:11)
    at startup (node.js:139:18)
    at node.js:968:3

Process finished with exit code 1

表示很懵逼啊,刚开始自学node.js表示不知从何调试下手,望高手指点。


3000端口被其他程序占用了。你换个端口吧

【热门文章】
【热门文章】