静的ファイルのロード要求を送信しようとするとNodejsエラーECONNREFUSED 127.0.0.1:3000が発生しました。私はこのエラーに関する多くの質問を見たことがありますが、明らかにこのエラーがなぜスローされるのかについてはまっすぐな答えはありません。以下は、私のコードです。私はlocalhostを127.0.0.1に変更しようとしましたが、ポート番号を3000,7000,8080に変更しましたが、何も解決しませんでした。誰かに助言してもらえますか?ありがとうございました。エラー:ECONNREFUSEDを接続してください。 Unhandled 'error'イベントNodeJS
//Basic web client retrieving content of file using get request
var http = require('http');
//options for request
var options = {
hostname: 'localhost',
port: '3000',
path: '../html/hello.html'
};
//function to handle response from request
function getResponse(response){
var serverData='';
response.on('data', function(chunk){
serverData += chunk;
});
response.on('end', function(){
console.log(serverData);
});
};
http.request(options, function(response, error){
getResponse(response);
}).end();
ありがとうございます。残念ながら、私がNodeを学ぶために使っているリソースは、サーバを事前に起動しておく必要があることを指摘しませんでした。ありがとう – Celaro