Javascript client for the Nexus Configuration Server
- Setup a Nexus server
- Require the library into your project:
npm require --save nexus-config-js
- Build a client and fetch configuration files for your app (Explained below)
This current version only works with Node.js (server-side) apps.
In order to create an instance of a client with need to provide it with two parameters:
- The address of the server (HTTP or HTTPS)
- The API that is specific to the app you are configuring
These parameters can be passed through environment variables or manually through an options object:
They client will look for a NEXUS_SERVER and NEXUS_APIKEY environment variables:
var NexusClient = require('nexus-client-js'),
clientInstance;
clientInstance = NexusClient.buildFromEnv();
clientInstance.fetch(function (collection) {
// Fetch configuration files here
});
Please note that this method will throw an error if the appropriate environment variables are not defined. You can check if they are present with NexusClient.isEnvPresent()
var NexusClient = require('nexus-client-js'),
clientInstance;
clientInstance = NexusClient.build(
'http://nexus.local',
'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
);
clientInstance.fetch(function (collection) {
// Fetch configuration files here
});
- fetch(callback): Fetches all the configuration files from the server and calls the callback with a ConfigurationCollection object
- ping(message, callback): Send a ping message to the server
- log(filename, files, callback): Push log lines to the server
- build(server, apiKey): Creates a new NexusClient from that uses the specified server and key (NexusClient)
- buildFromEnv(): Creates a new NexusClient from evironment variables, NEXUS_SERVER and NEXUS_APIKEY (NexusClient)
- isEnvPresent(): Returns a boolean indicating if NEXUS_SERVER and NEXUS_APIKEY are available (Boolean)
- getKeyAsString(key): Get a configuration file as a raw string (String)
- getKeyAsJson(key): Get a configuration file as a JSON object (Object)
- hasKey(key): Check whether or not a file is defined (Boolean)
- getApplicationName(): Gets the application name defined in Nexus (String)
- getApplicationDescription(): Gets the description of the application defined in Nexus (String)
- getAllKeys(): Gets all configuration files as strings (Object)