-
-
Notifications
You must be signed in to change notification settings - Fork 24
Express.js Example
Blake Niemyjski edited this page Dec 12, 2016
·
2 revisions
Add Exceptionless to your Express.js project and start collecting unhandled errors and 404s quickly.
To start, just add the following middleware to the bottom of your middleware definitions.
// This middleware processes any unhandled errors that may occur in your middleware.
app.use(function(err, req, res, next) {
client.createUnhandledException(err, 'express').addRequestInfo(req).submit();
res.status(500).send('Something broke!');
});
// This middleware processes 404’s.
app.use(function(req, res, next) {
client.createNotFound(req.originalUrl).addRequestInfo(req).submit();
res.status(404).send('Sorry cant find that!');
});
We have built a quick Express.js sample app you can play around with.
Run the sample app by following the steps below:
- Install Node.js
- Clone or download our repository from GitHub.
- Run
npm install
. This steps is required because we reference the exceptionless package from the root dist folder. - Navigate to the
example\express
folder via the command line (e.g., cd example\express) - Run
npm install
- Open app.js in your favorite text editor and set the apiKey.
- Run node app.js.
- Navigate to http://localhost:3000 in your browser to view the express app.
- To create an error, navigate to http://localhost:3000/boom
We recommend enabling debug logging by calling client.config.useDebugLogger();
. This will output messages to the console regarding what the client is doing. Please contact us by creating an issue on GitHub if you need assistance or have any feedback for the project.
Looking for General Exceptionless Documentation, UI Documentation, or Documentation for another Client?
Visit the Primary Exceptionless Documentation Page and go from there.