Answer the question
In order to leave comments, you need to log in
How to properly handle a file error?
Please tell me how to handle the error.
server.on("request", function(req, res) {
var file = fs.createReadStream(req.url || "index.html");
...
}
file.on("error", function(err) {
console.log(err);
});
Answer the question
In order to leave comments, you need to log in
Check again. This option works for me.
var file = fs.createReadStream("somefilethatnotexist.html");
file.on("error", (err) => {
console.log('I got error!');
});
server.on("error", (err) => {
console.log('I got error!');
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question