Skip to content

@layerfig/parser-toml

This parser allows you to load configuration from .toml files.

  1. Install the dependency.

    Terminal window
    npm install @layerfig/parser-toml
  2. Create your configuration files.

  3. Add the parser to your ConfigBuilder.

    import { ConfigBuilder } from "@layerfig/config";
    import tomlParser from "@layerfig/parser-toml";
    export const config = new ConfigBuilder({
    validate: (finalConfig, z) => {
    const schema = z.object({
    appURL: z.url(),
    port: z.number()
    })
    return schema.parse(finalConfig)
    },
    parser: tomlParser
    })
    .addSource("base.toml")
    .build();

Your application is now configured to parse these file formats.