Organizational Research By

Surprising Reserch Topic

Experts Most Trusted Topic


read a file in node js


read a file in node js  using -'node.js'

I'm quite puzzled with 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);
    }
});


File start.html is in the same directory with file that tries 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?
    

asked Sep 18, 2015 by sanjaypal1983
0 votes
4 views



Related Hot Questions



Government Jobs Opening


...