# JavaScript configuration libraries

JavaScript configuration libraries load an application's settings from environment variables, .env files, and config files. A loader searches known file locations and merges the values it finds into one settings object. These libraries keep API keys, ports, feature flags, and user preferences out of application code.

## Popularity

| Library | Monthly downloads | Stars | Last release | License |
| --- | --- | --- | --- | --- |
| [dotenv](#dotenv) | 1.0B | 20.6K | Nov 2026 | BSD-2-Clause |
| [Cosmiconfig](#cosmiconfig) | 667.8M | Not on GitHub | Aug 2026 | MIT |
| [ConfigArray](#eslint-config-array) | 601.0M | Not on GitHub | Nov 2026 | Apache-2.0 |
| [Lilconfig](#lilconfig) | 403.3M | Not on GitHub | Nov 2026 | MIT |
| [rc](#rc) | 225.5M | Not on GitHub | May 2018 | (BSD-2-Clause OR MIT OR Apache-2.0) |
| [c12](#conetwo) | 152.4M | Not on GitHub | Oct 2026 | MIT |
| [Conf](#conf) | 99.1M | Not on GitHub | Oct 2026 | MIT |
| [Configstore](#configstore) | 98.0M | Not on GitHub | Jan 2026 | BSD-2-Clause |

Downloads: npm, last thirty days. Stars and releases: GitHub. Amber: no release in over a year.

[dotenv](#dotenv) has the most monthly downloads in this comparison, at 1.0B.

## Capabilities

| Library | YAML config files | Schema validation | Per-file overrides | Writes config files | Built-in .env loader |
| --- | --- | --- | --- | --- | --- |
| [dotenv](#dotenv) | No | No | No | No | Yes |
| [Cosmiconfig](#cosmiconfig) | Yes | No | No | No | No |
| [ConfigArray](#eslint-config-array) | No | Yes | Yes | No | No |
| [Lilconfig](#lilconfig) | Via plugin | No | No | No | No |
| [rc](#rc) | No | No | No | No | No |
| [c12](#conetwo) | Yes | Yes | No | Via plugin | Yes |
| [Conf](#conf) | Via plugin | Yes | No | Yes | No |
| [Configstore](#configstore) | No | No | No | Yes | No |

## Libraries

### dotenv

[GitHub](https://github.com/motdotla/dotenv) · [npm](https://www.npmjs.com/package/dotenv) · [Docs](https://cdn.jsdelivr.net/npm/dotenv@18.0.10/README.md)

Loads environment-file values into process.env or a supplied target object.

- Downloads / mo: 1.0B
- Stars: 20.6K
- Last release: 18.0.10
- License: BSD-2-Clause
- Capabilities: [From the dotenv docs](https://cdn.jsdelivr.net/npm/dotenv@18.0.10/README.md)

**Strengths**

- **Loads environment files directly.** Load file values early in application startup.
- **Supports a separate target object.** Pass processEnv to populate a supplied object instead of process.env.

**Watch out for**

- **Existing values win by default.** Set override to replace variables already present in the target.
- **Variable expansion needs another tool.** Use a separate expansion package for references between variables.

```sh
npm install dotenv@18.0.10
```

**nrwl/nx** (29.5K stars)

[nrwl/nx](https://github.com/nrwl/nx) 

```javascript
export function loadRootEnvFiles(root = workspaceRoot) {
  const myEnv = loadDotEnvFile({
    path: ['.local.env', '.env.local', '.env'].map((file) => join(root, file)),
  });
  expand(myEnv);
}

```

[packages/nx/src/utils/dotenv.ts](https://github.com/nrwl/nx/blob/03198dd15f1be45fe1b749fd0eb834403c49aa66/packages/nx/src/utils/dotenv.ts#L12-L17) · [More projects using dotenv →](https://dashboard.exa.ai/playground/search?q=JavaScript%20applications%20using%20dotenv%20for%20configuration%20loading%2C%20layered%20sources%2C%20type%20conversion%20and%20startup%20validation&filters=%7B%22type%22%3A%20%22auto%22%2C%20%22numResults%22%3A%2010%2C%20%22includeDomains%22%3A%20%5B%22github.com%22%5D%7D)

**Quickstart**

```javascript
// Explicit fixture: create .env containing HELLO="Dotenv" first.
import dotenv from 'dotenv';

dotenv.config();
console.log(process.env.HELLO);

```

From [README.md](https://cdn.jsdelivr.net/npm/dotenv@18.0.10/README.md)

### Cosmiconfig

[GitHub](https://github.com/cosmiconfig/cosmiconfig) · [npm](https://www.npmjs.com/package/cosmiconfig) · [Docs](https://cdn.jsdelivr.net/npm/cosmiconfig@10.0.1/README.md)

Searches for and loads a program's configuration.

- Downloads / mo: 667.8M
- Last release: 10.0.1
- License: MIT
- Capabilities: [From the Cosmiconfig docs](https://cdn.jsdelivr.net/npm/cosmiconfig@10.0.1/README.md)

**Strengths**

- **Reads JSON, YAML, and JS rc files.** An rc file can be JSON, YAML, JavaScript, or TypeScript.
- **Reads package.json properties.** A property in package.json can hold the configuration instead of a file.

```sh
npm install cosmiconfig@10.0.1
```

**react-native-community/cli** (2.9K stars)

[react-native-community/cli](https://github.com/react-native-community/cli) 

```javascript
export async function readConfigFromDiskAsync(
  rootFolder: string,
): Promise<UserConfig> {
  const explorer = cosmiconfig('react-native', {
    stopDir: rootFolder,
    searchPlaces,
  });

  const searchResult = await explorer.search(rootFolder);
  return parseUserConfig(searchResult);
}

```

[packages/cli-config/src/readConfigFromDisk.ts](https://github.com/react-native-community/cli/blob/2574a3a1968f12577c4f34d48190c31ce31a9593/packages/cli-config/src/readConfigFromDisk.ts#L40-L50) · [More projects using Cosmiconfig →](https://dashboard.exa.ai/playground/search?q=cosmiconfig%20GitHub%20projects)

**Quickstart**

```javascript
import { cosmiconfig } from 'cosmiconfig';

const explorer = cosmiconfig('myapp');
const result = await explorer.search();

```

From [README.md](https://cdn.jsdelivr.net/npm/cosmiconfig@10.0.1/README.md)

### ConfigArray

[GitHub](https://github.com/eslint/rewrite) · [npm](https://www.npmjs.com/package/@eslint/config-array) · [Docs](https://cdn.jsdelivr.net/npm/@eslint/config-array@0.23.6/README.md)

Matches configuration objects to files by glob patterns on their filenames.

- Downloads / mo: 601.0M
- Last release: 0.23.6
- License: Apache-2.0
- Capabilities: [From the ConfigArray docs](https://cdn.jsdelivr.net/npm/@eslint/config-array@0.23.6/README.md)

**Strengths**

- **Works outside ESLint.** The package carries no ESLint-specific functionality.
- **Later objects override earlier ones.** A config object later in the array overrides the objects before it.

```sh
npm install @eslint/config-array@0.23.6
```

**eslint/eslint** (27.6K stars)

[eslint/eslint](https://github.com/eslint/eslint) 

```javascript
normalize(context) {
	return super.normalize(context).catch(error => {
		if (error.name === "ConfigError") {
			throw wrapConfigErrorWithDetails(
				error,
				this[originalLength],
				this[baseLength],
			);
		}

		throw error;
	});
}

```

[lib/config/flat-config-array.js](https://github.com/eslint/eslint/blob/48207902fccd37450823b8fd07736d84449ec8e7/lib/config/flat-config-array.js#L137-L149) · [More projects using ConfigArray →](https://dashboard.exa.ai/playground/search?q=%40eslint/config-array%20GitHub%20projects)

**Quickstart**

```javascript
import path from 'node:path';
import { ConfigArray } from '@eslint/config-array';

const configs = new ConfigArray([{ files: ['**/*.js'], enabled: true }], {
  basePath: process.cwd(),
  schema: { enabled: {
    merge: (a, b) => b ?? a,
    validate(value) {
      if (typeof value !== 'boolean') throw new TypeError('Boolean expected.');
    },
  } },
});
configs.normalizeSync();
const config = configs.getConfig(path.resolve('example.js'));

```

From [README.md](https://cdn.jsdelivr.net/npm/@eslint/config-array@0.23.6/README.md)

### Lilconfig

[GitHub](https://github.com/antonk52/lilconfig) · [npm](https://www.npmjs.com/package/lilconfig) · [Docs](https://cdn.jsdelivr.net/npm/lilconfig@3.1.5/readme.md)

Provides a zero-dependency alternative to Cosmiconfig with the same API.

- Downloads / mo: 403.3M
- Last release: 3.1.5
- License: MIT
- Capabilities: [From the Lilconfig docs](https://cdn.jsdelivr.net/npm/lilconfig@3.1.5/readme.md)

**Watch out for**

- **No YAML by default.** Add a loader to read YAML files.
- **ESM needs the async API.** ESM config files load only through the asynchronous API.

```sh
npm install lilconfig@3.1.5
```

**storybookjs/storybook** (91.6K stars)

[storybookjs/storybook](https://github.com/storybookjs/storybook) 

```javascript
async function postCssFindConfig(path: string, options: Options = {}) {
  const result = await config.lilconfig('postcss', withLoaders(options)).search(path);

  return result ? result.filepath : null;
}

```

[code/frameworks/nextjs-vite/src/find-postcss-config.ts](https://github.com/storybookjs/storybook/blob/95fc98fef1f785be5162b2fd23c05265f2435ca3/code/frameworks/nextjs-vite/src/find-postcss-config.ts#L60-L64) · [More projects using Lilconfig →](https://dashboard.exa.ai/playground/search?q=lilconfig%20GitHub%20projects)

**Quickstart**

```javascript
import { lilconfig } from 'lilconfig';

const result = await lilconfig('myapp').search();

```

From [readme.md](https://cdn.jsdelivr.net/npm/lilconfig@3.1.5/readme.md)

### rc

[GitHub](https://github.com/dominictarr/rc) · [npm](https://www.npmjs.com/package/rc) · [Docs](https://cdn.jsdelivr.net/npm/rc@1.2.8/README.md)

Returns an app's configuration merged with the defaults it specifies.

- Downloads / mo: 225.5M
- Last release: 1.2.8
- License: (BSD-2-Clause OR MIT OR Apache-2.0)
- Capabilities: [From the rc docs](https://cdn.jsdelivr.net/npm/rc@1.2.8/README.md)

**Strengths**

- **Records the files it read.** The returned object lists the path of every config file found.

**Watch out for**

- **Mutates a passed defaults object.** Pass a fresh object when the defaults must stay unchanged.

```sh
npm install rc@1.2.8
```

**Strider-CD/strider** (4.6K stars)

[Strider-CD/strider](https://github.com/Strider-CD/strider) 

```javascript
function getConfig() {
  process.env = filterEnv(deprecated(process.env), envDefaults);
  const rc = require('rc')('strider', defaults);

  if (!rc.smtp) rc.smtp = smtp(rc);
  if (!rc.smtp) rc.stubSmtp = true;

  rc.ldap = getConfigByName('ldap');

  addPlugins(rc, process.env);

  // BACK COMPAT until we get strider config into plugins...
  if (hasGithub) {
    rc.plugins.github = rc.plugins.github || {};
    rc.plugins.github.hostname = rc.server_name;
  }

  debug(rc);

  return rc;
}

```

[apps/strider/lib/libconfig.js](https://github.com/Strider-CD/strider/blob/5287e2dec457b26c1694c6d08482c872e4d06d3c/apps/strider/lib/libconfig.js#L74-L94) · [More projects using rc →](https://dashboard.exa.ai/playground/search?q=rc%20GitHub%20projects)

**Quickstart**

```javascript
import rc from 'rc';

const config = rc('myapp', { port: 3000 });

```

From [README.md](https://cdn.jsdelivr.net/npm/rc@1.2.8/README.md)

### c12

[GitHub](https://github.com/unjs/c12) · [npm](https://www.npmjs.com/package/c12) · [Docs](https://cdn.jsdelivr.net/npm/c12@4.0.0-rc.4/README.md)

Merges configuration from multiple sources into one object.

- Downloads / mo: 152.4M
- Last release: 4.0.0-rc.4
- License: MIT
- Capabilities: [From the c12 docs](https://cdn.jsdelivr.net/npm/c12@4.0.0-rc.4/README.md)

**Strengths**

- **Reloads on change.** A config watcher reloads settings when a config file changes.
- **Loads .env files.** .env files load with variable interpolation.

**Watch out for**

- **Major upgrade needs migration.** Follow the migration guide when upgrading between major versions.

```sh
npm install c12@4.0.0-rc.4
```

**Quickstart**

```javascript
import { loadConfig } from 'c12';

const { config } = await loadConfig({});

```

From [README.md](https://cdn.jsdelivr.net/npm/c12@4.0.0-rc.4/README.md) · [Find projects using c12 →](https://dashboard.exa.ai/playground/search?q=c12%20GitHub%20projects)

### Conf

[GitHub](https://github.com/sindresorhus/conf) · [npm](https://www.npmjs.com/package/conf) · [Docs](https://cdn.jsdelivr.net/npm/conf@16.0.0/readme.md)

Persists small app settings to a JSON file without the app choosing where or how.

- Downloads / mo: 99.1M
- Last release: 16.0.0
- License: MIT
- Capabilities: [From the Conf docs](https://cdn.jsdelivr.net/npm/conf@16.0.0/readme.md)

**Watch out for**

- **One writer at a time.** Avoid writing to the same store from two processes at once.
- **Rewrites the whole file.** Keep the store small, such as user settings that change occasionally.

```sh
npm install conf@16.0.0
```

**Quickstart**

```javascript
import Conf from 'conf';

const config = new Conf({ projectName: 'my-app' });
config.set('enabled', true);

```

From [readme.md](https://cdn.jsdelivr.net/npm/conf@16.0.0/readme.md) · [Find projects using Conf →](https://dashboard.exa.ai/playground/search?q=conf%20GitHub%20projects)

### Configstore

[GitHub](https://github.com/sindresorhus/configstore) · [npm](https://www.npmjs.com/package/configstore) · [Docs](https://cdn.jsdelivr.net/npm/configstore@8.0.0/readme.md)

Loads and saves app settings in a JSON file under the user's config directory.

- Downloads / mo: 98.0M
- Last release: 8.0.0
- License: BSD-2-Clause
- Capabilities: [From the Configstore docs](https://cdn.jsdelivr.net/npm/configstore@8.0.0/readme.md)

**Watch out for**

- **Superseded by Conf.** The authors point new projects to Conf as the newer version.

```sh
npm install configstore@8.0.0
```

**GoogleChrome/lighthouse** (31.2K stars)

[GoogleChrome/lighthouse](https://github.com/GoogleChrome/lighthouse) 

```javascript
function askPermission() {
  return Promise.resolve().then(_ => {
    const configstore = new Configstore('lighthouse');
    const isErrorReportingEnabled = configstore.get('isErrorReportingEnabled');
    if (typeof isErrorReportingEnabled === 'boolean') {
      return Promise.resolve(isErrorReportingEnabled);
    }

    return prompt()
      .then(response => {
        configstore.set('isErrorReportingEnabled', response);
        return response;
      });
  // Error accessing configstore; default to false.
  }).catch(_ => false);
}

```

[cli/sentry-prompt.js](https://github.com/GoogleChrome/lighthouse/blob/ae9c80854a5d73a1a0c42be3e088d2648293ae80/cli/sentry-prompt.js#L61-L76) · [More projects using Configstore →](https://dashboard.exa.ai/playground/search?q=configstore%20GitHub%20projects)

**Quickstart**

```javascript
import Configstore from 'configstore';

const config = new Configstore('my-app');
config.set('enabled', true);

```

From [readme.md](https://cdn.jsdelivr.net/npm/configstore@8.0.0/readme.md)

## FAQ

### What is dotenv?

[dotenv](#dotenv) loads the key and value pairs in a .env file into process.env, or into an object the app supplies. Without override, a value already present in process.env is left unchanged.

### How do I use environment variables in Node.js?

Node.js exposes environment variables on process.env. [dotenv](#dotenv) fills process.env from a .env file at startup. [c12](#conetwo) loads .env files together with config files.

### What is Cosmiconfig?

[Cosmiconfig](#cosmiconfig) searches for and loads a program's configuration from a package.json property or an rc file in JSON, YAML, or JavaScript.

### What is a good dotenv alternative?

[c12](#conetwo) loads .env files with variable interpolation and merges them with config files. [rc](#rc) reads prefixed environment variables alongside command-line arguments and config files.

### Does dotenv perform variable expansion itself?

Its own README directs variable expansion to a separate tool.

### Can dotenv populate an object without changing process.env?

Pass a custom processEnv target to receive the loaded values.

## How this page was built

Data checked Nov 20, 2026.

Reproduce it with the Exa API:

```json
{
  "endpoint": "/search",
  "body": {
    "query": "Best JavaScript configuration libraries dotenv convict nconf envalid code examples",
    "numResults": 5
  }
}
```

Docs: https://exa.ai/docs/reference/search
