Electrode Hapi Web Server

3.3.0 · active · verified Tue Apr 21

Electrode Server is a configurable web server built atop Hapi.js and Node.js, designed to standardize the setup and serving of web applications. The current stable version is 3.3.0. It provides a baseline Hapi server instance that can be extended primarily through configuration, reducing the need for boilerplate code and duplicated server setup logic across projects. While offering default settings that allow for a quick startup, its strength lies in its extensive configuration options, managed optionally by tools like `electrode-confippet`, enabling fine-grained control over Hapi server and connection settings, including port, host, compression, and plugin registration. It simplifies the integration of Hapi plugins by providing a structured way to register them. Electrode Server aims to abstract away common server setup concerns, allowing developers to focus on application-specific features and logic. The package does not explicitly detail its release cadence, but minor versions are released as needed.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates starting an Electrode server on a custom port with a basic Hapi route registered via the plugin configuration.

const config = {
  connection: {
    host: process.env.HOST ?? 'localhost',
    port: parseInt(process.env.PORT ?? '3000', 10),
    routes: {
      cors: true
    }
  },
  plugins: {
    'my-routes-plugin': {
      register: (server, options) => {
        server.route({
          method: 'GET',
          path: '/',
          handler: (request, h) => {
            return 'Hello, Electrode Server!';
          }
        });
      },
      options: {}
    }
  }
};

require('electrode-server')(config);

console.log(`Electrode Server running on http://${config.connection.host}:${config.connection.port}`);

view raw JSON →