3

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?

tommyd456
  • 10,443
  • 26
  • 89
  • 163

2 Answers2

3

Check out this answer to another question on SO. It describes a method to use app.get() and app.set() to access dependencies across the application.

After you configure client, set it in the app:

app.set('keen', client);

Then later get it back out from within any route:

var client = app.get('keen');
Community
  • 1
  • 1
Josh Dzielak
  • 1,803
  • 17
  • 19
1

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.

tommyd456
  • 10,443
  • 26
  • 89
  • 163