index.js
function (res, errorCode, errorMessage) {
    res.writeHead(errorCode, {"Content-Type": "text/html"});
    //Read the local error file
    return fs.readFile(options.error, "utf8", function (error, content) {
        //Check the error
        if (error) {
            return res.end("<" + "h1>Error</h1><p>" + errorMessage + "</p>");
        }
        let data = {code: errorCode, message: errorMessage};
        content = content.replace(/{{([^{}]+)}}/g, function(match, found)
            {
                found = found.trim();
                if(typeof data[found] !== "undefined") {
                    return data[found].toString();
                } else {
                    return match;
                }
            });
        return res.end(content);
    });
}
function (res, errorCode, errorMessage) {
    res.writeHead(errorCode, {"Content-Type": "text/html"});
    //Read the local error file
    return fs.readFile(options.error, "utf8", function (error, content) {
        //Check the error
        if (error) {
            return res.end("<" + "h1>Error</h1><p>" + errorMessage + "</p>");
        }
        let data = {code: errorCode, message: errorMessage};
        content = content.replace(/{{([^{}]+)}}/g, function(match, found)
            {
                found = found.trim();
                if(typeof data[found] !== "undefined") {
                    return data[found].toString();
                } else {
                    return match;
                }
            });
        return res.end(content);
    });
}
function ( res , errorCode , errorMessage ) { res . writeHead ( errorCode , { "Content-Type" : "text/html" } ) ; //Read the local error file return fs . readFile ( options . error , "utf8" , function ( error , content ) { //Check the error if ( error ) { return res . end ( "<" + "h1>Error</h1><p>" + errorMessage + "</p>" ) ; } let data = { code : errorCode , message : errorMessage } ; content = content . replace ( / {{([^{}]+)}} / g , function ( match , found ) { found = found . trim ( ) ; if ( typeof data [ found ] !== "undefined" ) { return data [ found ] . toString ( ) ; } else { return match ; } } ) ; return res . end ( content ) ; } ) ; }
Display an error page
Display an error page