Expressify’s app factory. This module exports a function you can use to create and configure an express app. With some often used settings and middlewares.

Options

  • body: Object to configure the body-parser middleware. Subkeys map to methods on body-parser, passing true will call the method without options while setting an object will pass that object to body parser. Defaults to { json: true } to enable JSON formatted body parsing.
  • compression: Enable compression middleware. Use true to enable or an object to customize options. Defaults to true.
  • cors: Enable Expressify’s CORS middleware. Use true to enable or an object to customize its options. Defaults to true.
  • express: Use this to pass in a custom express module. Defaults to the express module defined in Expressify’s dependencies.
  • trustProxy: Set express’ trust proxy setting. Defaults to true.
  • logger: A @ambassify/bunyan-logger compatible logger instance.
  • gracefulShutdown: Handles SIGTERM and SIGINT signals to gracefully shutdown the http server using http-shutdown. Defaults to true
  • gracefulShutdown.callback: a callback function (may be async) called when the server has shutdown. May be used to close database connections. Defaults to lodash/noop.
  • gracefulShutdown.forceTimeout: milliseconds to wait before forcing process.exit(1) if shutdown hasn’t completed. Defaults to 30000. Set to 0 to disable.

Example

const expressify = require('@ambassify/expressify');

// Default options
const app = expressify.createApp();

// URL encoded body instead of JSON
const app = expressify.createApp({
    body: {
        urlencoded: true
    }
});