I have created a simple filereader method in node.js that takes in an html file in the same folder. However, when I try to launch it on my localhost, I receieve the message: throw new TypeError<'First argument must be a string or Buffer'>;
My node.js file is:
var http = require('http');
var fs = require('fs');
http.createServer(function (req, res) {
fs.readFile('demofile1.html', function(err, data) {
res.writeHead(200, {'Content-Type': 'text/html'});
res.write(data);
res.end();
});
}).listen(8080);
And my HTML code is simple as well:
<html>
<body>
<h1>My Header</h1>
<p>My paragraph.</p>
</body>
</html>
If someone could please provide some insight, it would be much appreciated. I looked on both Google and StackOverflow and no solutions fixed my problem. Other node programs like outputting "Hello World" or displaying the date and time work on my localhost.
if (err) { console.error(err); }to yourreadFilecallback, it's probably a path issue