node.js unhandled 'error' event

1
'use strict'

const http = require('http');


http.get({
    hostname: 'localhost',
    path: '/user?name=jv&jovem=true&agr=19',
    port: 3000,
    agent: false
}, function(response) {
    let body = "";
    console.log('STATUS:' + response.statusCode);
    console.log('HEADERS:' + response.headers);
    response.on('data', function (data) {
        body += data;
    });

    response.on('end', function () {
        console.log('Resposta:', body);
    });
});

When I run the console, the error appears:

unhandled 'error' event
Error: connect ECONNREFUSED IP:3000
at Object.exports._errnoException (util.js:1085:14)
at exports._exceptionWithHostPort (util.js:1049:20)
at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1085:14)
    
asked by anonymous 04.12.2016 / 19:30

0 answers