npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

eea-searchserver

v0.0.26

Published

EEA Node.js Search Server module

Readme

eea.searchserver.js

Node.js search server library for EEA search apps

To be used with an express Node.js application

Features

  • 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

Install

npm install eea-searchserver

Contents

Server

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
    "host":
      "my-elastic-host", // Host running an Elastic Server (required)
    "path":
      "/elastic/",       // Path on host to the Elastic Server (default /)
    "port": 80,          // Port on which Elastic listens (default 9200)
    "index":
      "data",            // Index to be queried (required)
    "type":
      "resource"         // Type to be queried (required)
  },
  "external_templates": { // External template service (optional)
    "local_path":
      "/path/to/external_templates", // Path to save external templates locally
    "host":
      "www.eea.europa.eu",          // Host to query for external templates
    "head_path":                    // Path on host for the page HEAD
      "/templates/v2/getRequiredHead?jsdisable=all",
    "header_path":                  // Path on host for the page HEADER
      "/templates/v2/getHeader?jsdisable=all",
    "footer_path":                  // Path on host for the page FOOTER
      "/templates/v2/getFooter"
  }
}

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
server.run('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
server.run('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");
}

Routes

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();
app.post('/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();
app.post('/api', eeasearch.routes.elasticProxy);

Middleware

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();
app.use(eeasearch.middleware.templateRequired);

Util

On demand template loading

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

eeasearch.util.invalidateTemplates()

esAPI

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
}
esAPI(options).DELETE("/index/type/_mappings",
                      function(err, code, header, body) {
                        // Code can be any valid HTTP code
                        // HTTP error codes (500, 403, ...)
                        // are not marked as errors
                        CallbackLogic();
                      })
              .PUT("/index/type/_mappings",
                      function(err, code, header, body) {
                        OtherLogic();
                      })
              .execute();