node package manager
Share your code. npm Orgs help your team discover, share, and reuse code. Create a free org »



Node.js search server library for EEA search apps

To be used with an express Node.js application


  • Proxy for any Elastic backend (so Elastic doesn't have to be exposed publicly)
  • EEA Template Invalidation Routines
    • Automatic template loading if templates do not exist locally
    • On demand template loading via routes or util function
  • API for Elastic management commands
  • Framework for easily adding index management commands
  • Entrypoint for any of EEA's Elastic Search Docker applications


npm install eea-searchserver



Initial setup

Start by writing the base configurtion file:

  "http": {
    "port": 8080         // Port on which the app will listen, default(3000) 
  "elastic": {           // Remote Elastic Endpoint configuration 
      "my-elastic-host", // Host running an Elastic Server (required) 
      "/elastic/",       // Path on host to the Elastic Server (default /) 
    "port": 80,          // Port on which Elastic listens (default 9200) 
      "data",            // Index to be queried (required) 
      "resource"         // Type to be queried (required) 
  "external_templates": { // External template service (optional) 
      "/path/to/external_templates", // Path to save external templates locally 
      "",          // Host to query for external templates 
    "head_path":                    // Path on host for the page HEAD 
    "header_path":                  // Path on host for the page HEADER 
    "footer_path":                  // Path on host for the page FOOTER 

Running a simple express app

var eeasearch = require('eea-searchserver');
// create a base app 
var app = express();
// load app settings 
var settingsFile = '/path/to/settings.json';
// create server 
server = eeasearch.Server(app, settingsFile)
// start the app'runserver', [], function(err, server) {
    console.log("Started server");

Easy to add management commands:

var eeasearch = require('eea-searchserver');
// create a base app 
var app = express();
// add management commands 
app.set('managementCommands', {'cmd': function(args) { console.log(args); }});
// load app settings 
var settingsFile = '/path/to/settings.json';
// create server 
server = eeasearch.Server(app, settingsFile, function(err, server) {
    if (err) console.log("The app was poorly configured: " + err.message);
// start the app'cmd', ['foo', 'bar'], function(err, server) {
    if (err) {
        console.log("Something went wrong when running the command");
    console.log("Ran custom command, should see ['foo', 'bar'] on screen");


Invalidate Templates

Any POST request to invalidate_templates will get the templates from the host which was set up in the settings.json file and save them to the local path.

var app = express();'/invalidate_templates', eeasearch.routes.invalidateTemplates);

Elastic Proxy

Any GET request with the parameter source set as a valid Elastic query or Any POST request with the body an valid Elastic query will be forwarded to the Elastic host set up in the settings.json file.

The queries will be carried out to the index and type configured in settings.json .

var app = express();'/api', eeasearch.routes.elasticProxy);


Automatic template loading

Use this to load templates automatically on the first request on the app. This will ensure that the external templates exist on disk before rendering the page.

var app=express();


On demand template loading

This will send requests and update the external templates using the configuration in settings.json



A lightweight REST api for Elastic index management commands. To chain the commands use chained calls like in the following example. Otherwise, the order of the requests is asynchronous.

The REST calls are executed when .execute() is called. If any error occurs while executing a request, the others are not run.

Note:. This API does not use settings.json configured Elastic host Note:. A successful run means any response from the server (500, 200, etc.)

var options = {
    "es_host": "http://host:port/path/to/endpoint",
    "auth": {"user": user, "pass": pass} # optional if elastic needs auth
                      function(err, code, header, body) {
                        // Code can be any valid HTTP code 
                        // HTTP error codes (500, 403, ...) 
                        // are not marked as errors 
                      function(err, code, header, body) {