I am very puzzled by reading files in 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); } });
The start.html file is in the same directory as the file that is trying to open and read it.
However, in the console, I get:
{[Error: ENOENT, open './start.html'] errno: 34, code: 'ENOENT', path: './start.html'}
Any ideas?
Eugene Kostrikov Aug 22 '13 at 16:43 2013-08-22 16:43
source share