How do I turn off Node.js Express (ejs template engine) errors for production? -
when i'm on development server , there error, express sends traceback response.
however, not production. don't want seeing trackback.
how can turn off?
note: i'm using ejs template engine - may cause, , not express. when have undefined variable in ejs template, example, ejs renders traceback , displays user on white page.
the latest version of express use smart default error handler.
in development
mode sends full stack trace browser, while in production
mode sends 500 internal server error
.
to take advantage of should set proper node_env
before running application.
for example, run app in production mode:
node_env=production node application.js
but if don't default behavior, define own error handler:
app.use(function(err, req, res, next){ console.error(err); res.status(500); res.render('error'); });
note error handler must last middleware in chain, should defined in bottom of application.js
file.
if need more information, see:
Comments
Post a Comment