npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

@veikkaus/node-config

v0.6.0

Published

Rescript configuration library for nodejs

Downloads

2

Readme

VeikkausNodeConfig

npm version ci tests

Config library for nodejs, similar to node-config but strongly typed with validated type parsing. No need for Js.Nullable.t shims typical when just binding to js-libs. Configuration data is a JSON Object loaded by a loader function (see below).

Install

npm install @veikkaus/node-config

And to bsconfig.json: "bs-dependencies": [..., "@veikkaus/node-config", ...],

Usage Examples

Assuming You Write file MyConfig.res:

module C = VeikkausNodeConfig.Config;

/*
 * loadConfig with default options searches for .json and .yaml files from ./config/
 * (loading may produce an error, therefore using getExn, which will throw if loading had errors)
 */
let config: C.t = C.loadConfig() -> C.getExn;

Usage in other files/modules:

module C = VeikkausNodeConfig.Config;
let config = MyConfig.config;

let host: string = C.getString(config, "server.host");
let port: int = C.getInt(config, "server.port");
let flag: bool = C.getBool(config, "featureX");
let factorZ: float = C.getFloat(config, "z.factor");
let strList: list<string> = C.getList(config, "example.abc", C.parseString);
let intDict: Js.Dict.t<int> = C.getDict(config, "example.def", C.parseInt);

/* Functions above are convenience functions combining a couple of other functions in this library.
 * These `get*` functions will throw errors if configuration value is not found or is not expected type.
 * If you wish to handle errors differently it is possible to extract the configuration value as Belt.Result.t
 */

/* Custom parsing is also supported. This can be useful for mapping heterogenous configuration objects into rescript object types */
type student;
let myParser: Js.Json.t => student;     /* This you need to provide. Throws errors if cannot convert. */

let confStudent: student = config -> C.key("example.x") -> C.parseCustom(myParser) -> C.getExn;

See src/Config.resi for full list of config value getters.

Config loading

Function C.loadConfig() searches config values from following sources in following order:

  1. Loads config files from directory defined by NODE_CONFIG_DIR env variable if it exists, or otherwise from directory process.cwd() + "/config/":
    1. File default.{json,yaml} is loaded if it exists
    2. File ${NODE_CONFIG_ENV}.{json,yaml} is loaded if it exists, and if not, then and only then ${NODE_ENV}.{json,yaml} is loaded if that exists.
    3. File local.{json,yaml} is loaded if exists.
  2. Loads Environment Variables
    1. Loads CONFIG_JSON contents
    2. Reads file custom-environment-variables.{json,yaml}, which contains ENV variable name override definitions for various config keys (this is identical to: node-config), -> loads overrides from the defined env variables that are found. JSON parsing is attempted to the values of the env variables, enabling e.g. passing lists inside one env variable: MYVAR='["first","second"]'. If the attempted JSON parsing fails, the value is treated as a simple string e.g. MYVAR2="value2" (= simple string. note that json would need extra quotations: "\"value2\"")
  3. Fallback to empty config if nothing from the above exists.