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 rotate on 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)
Forehead join
.on('error', (e) => console.log(e));
to catch that mistake, put it at the end of your code, before;
– Sergio
on the console appeared: code: 'enconnrefused', Errno: 'enconnrefused', syscall: 'connect' address: 'myIP', port: 3000
– Shintaro Ryoushi
You have the server running on the localhost?
– Sergio