Node.js http.createServer how to get error

后端 未结 4 515
广开言路
广开言路 2020-12-16 13:31

I am new to node.js and am trying to experiment with basic stuff.

My code is this

var http = require(\"http\");
http.createServer(function(request,          


        
4条回答
  •  旧时难觅i
    2020-12-16 13:50

    You can do this by handling the error event on the server you are creating. First, get the result of .createServer().

    var server = http.createServer(function(request, response) {
    

    Then, you can easily handle errors:

    server.on('error', function (e) {
      // Handle your error here
      console.log(e);
    });
    

提交回复
热议问题