# Express App

Nodewood uses Express to serve web requests for the API. This app is built in wood/lib/src/AppBuilder.js. This class has a variety of methods that can be overridden in order to customize the app as necessary for the your purposes.

# Adding Error Trackers

Error tracking is an important service that many people add to their Express apps. You can use AppBuilder's beforeMiddlewareAdded and afterMiddlewareAdded to add the handlers to enable these services.

For example, assuming you're adding Honeybadger, create your own app/lib/src/AppBuilder.js:

const Honeybadger = require('honeybadger').configure({
  apiKey: process.env.HONEYBADGER_API_KEY,
});
const { AppBuilder: AppBuilderWood } = require('@wood-api/AppBuilder');

class AppBuilder extends AppBuilderWood {
  /**
   * Called before any other middleware is added, to allow for error handling middleware to be
   * initialized.
   *
   * @param {Express} app - The express app to add to.
   *
   * @return {Express}
   */
  async beforeMiddlewareAdded(app) {
    app.use(Honeybadger.requestHandler);

    return app;
  }

  /**
   * Called after any other middleware is added, to allow for error handling middleware to be
   * finalized.
   *
   * @param {Express} app - The express app to add to.
   *
   * @return {Express}
   */
  async afterMiddlewareAdded(app) {
    app.use(Honeybadger.errorHandler);

    return app;
  }
}

module.exports = { AppBuilder };