Skip to content

Configuration

Tyler Swayne edited this page Oct 29, 2023 · 4 revisions

Nexi has several configurable elements that you can adjust in src/config/config.js, as well as a few other components that you can define within the config directory.

App config

As described in the app structure doc, the core application configuration file must exist at src/config/config.js. This file location is currently not configurable, however it is the only conventional file location that cannot be changed.

At the very least, the config.js file must export an object:

module.exports = {
  someApplicationConfig: 'some-value',
}

This object, combined with some Nexi specific configuration, is attached to the application context or passed directly to every Nexi component (middleware, controllers, boot, and decorators).

Configuring Nexi components

Nexi uses several third party packages for richer functionality within the framework. Most of these packages are configurable, the ones that are are configurable

Basics

The base Nexi config will use the src/config/config.js values for any application settings that are defined in that object, falling back to application defaults. Those settings are:

{
  rootDirectory: './',
  port: '../assets',
  devLogger: false,
  stage: 'development',
  apiMode: false
}
  • rootDirector: This defines where Nexi will look for every other component (outside of the config dir). This can be useful if your application has a server and client directory, or any other circumstance where you would like your application to be nested. In the client/server example, you would set this value to ./server, where your server directory contains app, decorators, routes and every other component defined by the app structure.
  • port: This specifies which port the application will attach to when running.
  • devLogger: If set to true, the application will use pino pretty to format log messages. Pino pretty is easier to read, but is not recommended for production usage.
  • stage: Stage is a convention for defining multiple environments, such as local, dev, staging, production, etc. Nexi's usage of this convention is fairly light, however there is one behavior that this does affect. If this value is development Nexi will set the displayError flag to true, which returns the any throw execution messages in the error response when in api mode. See api mode for more information.
  • apiMode: Toggles Api Mode, see the docs on Api Mode for more details.

Express

Nexi uses express under the hood for it's core web framework capabilities. Some express features are configurable through an expressSettings config:

{
  expressSettings: {
    bodyParser: {}
    trustProxy: null
  }
}
  • bodyParser: A config object that is passed directly to expresses body parser
  • trustProxy: Passed to express's trust proxy setting. This may be required if running your application behind a reverse proxy (such as nginx).

Helmet

Nexi wires helmet up to applications by default to promote and provide secure practices out of the box. Nexi passes config.helmet directly to the package, so any helmet configuration options/overrides be defined within that object.

Clone this wiki locally