using Raygun with multiple files

Nico

Posted on
Apr 16 2015

Hi!

I´m new to Raygun and have one last problem to solve.

My Node App is structured in one main file and several modules.

In the main file I include every module/file like this:

server = require("./modules/server.js")

Now when I init Raygun in the mainfile:

var raygun = require('raygun');

var raygunClient = new raygun.Client().init({ apiKey: 'mLFIGeTFit2dXBvO/RCFHA==' });

How can I access it in the second file?

I cannot init it again but the send command is

raygunClient.send(new Error('something bad happened'));

How can I make the raygunClient variable accessible in the second file?

Thanks!


Jamie Penney

Posted on
Apr 16 2015

Hey Nico,

I would put the Raygun setup into it's own js file, then require that from wherever you need it. Put something like this in a file called raygun.js:

var raygun = require('raygun');
var raygunClient = new raygun.Client().init({ apiKey: 'mLFIGeTFit2dXBvO/RCFHA==' });
module.exports.raygunClient = raygunClient;

Then wherever you need to use the client from, just add

var raygunClient = require('./raygun').raygunClient;

and use that how you normally would.


Nico

Posted on
Apr 16 2015

Thanks! That was exactly what I was looking for!


Reply