Przeczytaj plik w Node.js
Jestem zdziwiony czytaniem plików w 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);
}
});
Plikstart.html
znajduje się w tym samym katalogu z plikiem, który próbuje go otworzyć i przeczytać.
Jednak w konsoli otrzymuję:
{[Błąd: ENOENT, otwórz „./start.html”] errno: 34, kod: „ENOENT”, ścieżka: „./start.html”}
Jakieś pomysły?