Search code examples
node.jsexpresskeen-io

Sharing objects across routes


Trying out Keen.io and wondering if it's possible to NOT have to call "configure" in each file that will make a call to the Keen API?

Their docs from here: https://github.com/keenlabs/KeenClient-node show how to configure an instance which I use in one of my routes but I have a number of routes and find that I have to keep configuring.

var Keen = require('keen.io');

// Configure instance. Only projectId and writeKey are required to send data.
var client = Keen.configure({
  projectId: "<project_id>",
  writeKey: "<write_key>",
  readKey: "<read_key>",
  masterKey: "<master_key>"
});

Is there a way to "configure" just once or have I got the wrong idea?


Solution

  • I decided to configure the app inserver.js and then pass the client object to each route that requires it. This appears to work well and has tidied my code up considerably.