here is my function
function loadscript(request, callback){
fs.readFile('scripts/'+request.filename, function(err, data){
callback(data);
});
}
how can i pass that if file not exist then it should reply error to call back .
i tried fs.stat but one time it return the error.code to callback but second time when i call the function from the url of the server it gives the error.
The error it given with
TypeError: first argument must be a string, Array, or Buffer
at ServerResponse.write (http2.js:598:11)
at /home/reach121/basf/index.js:37:17
at /home/reach121/basf/index.js:81:3
at [object Object].<anonymous> (fs.js:81:5)
at [object Object].emit (events.js:67:17)
at Object.oncomplete (fs.js:948:12)
what should i used to solve this .
If you want to know whether there was an error loading the file, check if
erris notnull.If you only want to do something if the file can’t be found, you can check for
err.codebeing equal toENOENT: