8
Node.jsでファイルを読み取る
Node.jsでファイルを読み取ることに私はかなり困惑しています。 fs.open('./start.html', 'r', function(err, fileToRead){ if (!err){ fs.readFile(fileToRead, {encoding: 'utf-8'}, function(err,data){ if (!err){ console.log('received data: ' + data); response.writeHead(200, {'Content-Type': 'text/html'}); response.write(data); response.end(); }else{ console.log(err); } }); }else{ console.log(err); } }); ファイルstart.htmlは、それを開いて読み取ろうとするファイルと同じディレクトリにあります。 ただし、コンソールでは次のようになります。 {[エラー:ENOENT、オープン './start.html']エラー番号:34、コード: 'ENOENT'、パス: './start.html'} 何か案は?
186
node.js