With our Raygun4node package, you can provide a convenient way to send your node.js error to Raygun. It can be figure by using NPM installation:
It provides you with a Raygun client that you can use to configure your API key and can be used to manually send error messages. But later on you might say, "I don't want to send all the bugs to Raygun by hand, which sounds like a lot of work to do!" If you're using a express.js, the Express processor can easily solve the concern.
var Raygun = require (' Raygun ');
var raygunclient = new Raygun. Client (). Init ({apikey: ' Your API key '});
App.use (Raygunclient.expresshandler);
In other cases you may just want to listen for an exception uncaughtexception that has not been caught and send an error message in this way.
var Raygun = require (' Raygun ');
var raygunclient = new Raygun. Client (). Init ({apikey: ' Your API key '});
Process.on (' Uncaughtexception ', function (err) {
raygunclient.send (err);
});
If you're going to start doing this, you have to understand what it means. But when a time bubble goes back to the event loop, the event will be sent out. If you add a listener to this event, the default action will not happen again. The default action prints out the call stack information and exits the process. If you continue after this trigger, your node process will be in a state that is not defined. The Node.js document specifically mentions that you should not use this thing, and that it may be removed in the future. The recommended alternative is to use domain domains. Here's a small, simple example where you can see how Raygun clients fit in with your domain.
var domain = require (' domain ');
var Raygun = require (' Raygun ');
var raygunclient = new Raygun. Client (). Init ({apikey: ' Your API key '});
var server = require (' http '). Createserver (function (req, res) {
var d = domain.create ();
D.on (' Error ', function (err) {
raygunclient.send (err);
Clean up and End
});
D.add (req);
D.add (res);
D.run (function () {
//Handle the Req, res
});
Server.listen (3000);
Hopefully this will help you better understand the error handling in the Node.js using Raygun.
Continuous cleanup Error!