Configuration

How to configure Jeasx

Jeasx provides sensible defaults to get you started quickly, but it also allows you to override important settings with environment variables. This makes it easy to adapt the framework to your needs.

To facilitate managing multiple configurations, Jeasx leverages layers of .env-files. This enables the use of different .env-files based on the NODE_ENV value, such as .env.development to override values from .env for development. The order of loading .env-files is the same as it is used by the well-known dotenv-flow library. To load the env-files into process.env, Jeasx makes use of the native implementation provided by Node.js via process.loadEnvFile via a custom utility function. An existing environment variable will not be overwritten by subsequent files.

  1. .env.[NODE_ENV].local (e.g. .env.development.local or .env.production.local)
  2. .env.[NODE_ENV] (e.g. .env.development or .env.production)
  3. .env.local
  4. .env
  5. .env.defaults
  6. .env.js

Please note: Jeasx only sets NODE_ENV=development automatically when running jeasx dev. For production or testing environments, you'll need to set the NODE_ENV environment variable to the desired value (e.g. production or test) depending on your requirements and workflows.

The last environment file which may be optionally loaded is a JavaScript file which must export an default object containing the environment variables. Only variables which are not already set, will be populated into the environment. Here is an example .env.js file:

const NODE_ENV_IS_DEVELOPMENT = process.env.NODE_ENV === "development";

export default {
  ESBUILD_BROWSER_TARGET: "chrome130,edge130,firefox130,safari18",

  /** @type import("fastify").FastifyServerOptions */
  FASTIFY_SERVER_OPTIONS: {
    disableRequestLogging: NODE_ENV_IS_DEVELOPMENT,
    bodyLimit: 2 * 1024 * 1024,
    rewriteUrl: (req) => String(req.url).replace(/^/jeasx/, ""),
  },

  /** @type import("@fastify/static").FastifyStaticOptions */
  FASTIFY_STATIC_OPTIONS: {
    maxAge: NODE_ENV_IS_DEVELOPMENT ? 0 : "365d",
  },

  /** @type import("@fastify/cookie").FastifyCookieOptions */
  // FASTIFY_COOKIE_OPTIONS: {},

  /** @type import("@fastify/formbody").FastifyFormbodyOptions */
  // FASTIFY_FORMBODY_OPTIONS: {},

  /** @type import("@fastify/multipart").FastifyMultipartOptions */
  // FASTIFY_MULTIPART_OPTIONS: {},
};
Environment variables for client code

For security reasons, only environment variables prefixed with BROWSER_PUBLIC_ are accessible in client-side JavaScript to prevent accidental exposure of sensitive data. The values are only updated at build time, so changes to environment variables will require a rebuild to take effect.

Environment Variables

NameDescription
HOST

The hostname or IP address that the server should listen on. Defaults to :: which allows the server to listen on any interface (IPv4 or IPv6).

PORT

The port number that the server should listen on. Defaults to 3000.

BUILD_TIME

A read-only value set at build time and encoded as base36 (lower case alphabet and digits). Use it to create a cache busting parameter for loading JavaScript and CSS files.

ESBUILD_BROWSER_TARGET

Defaults to chrome130, edge130, firefox130, safari18, full documentation at esbuild website.

FASTIFY_SERVER_OPTIONS

Fastity-Server options reference, default options applied by Jeasx:

{"logger": true}

FASTIFY_STATIC_OPTIONSFastify-Static options reference, default options applied by Jeasx:
"root": [
  "/absolute/path/to/public",
  "/absolute/path/to/dist/browser"
],
"prefix": "/",
"wildcard": false,
"preCompressed": true
FASTIFY_MULTIPART_OPTIONSFastify-Multipart options reference, default options applied by Jeasx:
{"attachFieldsToBody": "keyValues"}
Fastify-Cookie options reference, default options applied by Jeasx:
{}
FASTIFY_FORMBODY_OPTIONSFastity-Formbody options reference, default options applied by Jeasx:
{}