Node.js Error: connect ECONNREFUSED

后端 未结 12 1190
小鲜肉
小鲜肉 2020-12-02 16:39

I am new to node and running into this error on a simple tutorial.

I am on the OS X 10.8.2 trying this from CodeRunner and the Terminal. I have also tried putting my

12条回答
  •  一个人的身影
    2020-12-02 17:10

    You need to have a server running on port 8080 when you run the code above that simply returns the request back through the response. Copy the code below to a separate file (say 'server.js') and start this server using the node command (node server.js). You can then separately run your code above (node app.js) from a separate command line.

    var http = require('http');
    
    http.createServer(function(request, response){
    
        //The following code will print out the incoming request text
        request.pipe(response);
    
    }).listen(8080, '127.0.0.1');
    
    console.log('Listening on port 8080...');
    

提交回复
热议问题