Tôi đã viết một mã đơn giản và lưu nó vào tệp try.js.Node.js unhandled 'error' event
var http = require('http');
var makeRequest = function(message) {
var options = {
host: 'localhost', port: 8080, path: '/', method: 'POST'
}
var request = http.request(options, function(response){
response.on('data', function(data){
console.log(data);
});
});
request.write(message);
request.end();
}
makeRequest("Here's looking at you, kid.");
Khi tôi chạy nó thông qua thiết bị đầu cuối nó đưa ra một lỗi
throw er; // Unhandled 'error' event,
Error: connect ECONNREFUSED
at errnoException (net.js:884:11)
at Object.afterConnect [as oncomplete] (net.js:875:19)error' event
tôi đã cố gắng để thay đổi cổng nhưng nó vẫn không làm việc – ana
câu hỏi của bạn là gì? Bạn muốn biết cách thêm trình xử lý lỗi cho sự kiện này? Hoặc bạn muốn biết lý do tại sao bạn nhận được một lỗi ở nơi đầu tiên? – hippietrail