Optionalenv_Environment variable file (.env) path, defaults to none (undefined).
Optionalcors_CORS permission, defaults to invalid (false).
Optionalmax_Maximum body size you can request, defaults to 100kb.
Optionalrouter_Absolute path to the router directory, defaults to <application root directory>/routes.
Optionaldefault_The endpoint to run when the root URL is requested, defaults to none (undefined).
Optionalrewrite_This is a hook that rewrites the base URL. If you want to rewrite the app.locals.baseUrl property and the view's baseUrl variable, use this hook to return a new base URL. The default value is the referrer's origin (eg https://example.com).
How to determine if it is an ajax request. The default is that if there is an XMLHttpRequest in the request header (req.xhr) returns true. For example, if there is no XMLHttpRequest in req(express.Request) and the Ajax endpoint starts with /api, a custom Ajax decision can be made like "return /^/api//.test(req.path)".
Optionalhook_Hooks the default behavior on request errors.
If unset, simply returns an error HTTP status. (res.status(error.status||500).end();)
hook_handle_error: (error, req, res, next) => {
if (error.status === 404)
// If the URL cannot be found, a 404 error screen (views/errors/404.hbs) is displayed.
res.render('errors/404');
else
// For other errors, unknown error screen (views/error/500.hbs) is displayed.
res.render('error/500');
},
Express Sweet basic application configuration interface. Defines configuration options for environment, CORS, routing, error handling, and more.
See
Express.js
Example