BASE

Cosmiconfig

Cosmiconfig

Backend / API library · Free

Configuration discovery and loading for JavaScript tooling: it helps your CLI support package.json and common config files.

Also known as: cosmiconfig/cosmiconfig; cosmiconfig

Resource illustration: Cosmiconfig

Open resource ↗

What you can use for free

Code and local use under MIT.

Paid features and costs

Computing resources, self-hosting, and external services are paid for separately if used.

Access and limitations

Code and local use under MIT. Computing resources, self-hosting, and external services are paid for separately if used.

Use cases

  • Add user configuration loading to a CLI
  • Connect config discovery and test the processing order of detected settings

Example workflow

A possible workflow; this is not a report of hands-on testing.

Add user configuration loading to a CLI.

Before you start

  • A data contract or HTTP workflow.
  • A project with a supported runtime.

Steps

  1. Define the tool name and supported configuration sources.
  2. Connect config discovery and test the processing order of detected settings.
  3. Add error handling and an integration check of the result.

Check your result

  • Invalid and missing data are handled predictably.
  • Types and the actual response agree; errors are not hidden.

Choosing Cosmiconfig

Add user configuration loading to a CLI

Choose this when

  • Add user configuration loading to a CLI
  • Connect config discovery and test the processing order of detected settings

Things to consider

  • Costs and limits of free use: Computing resources, self-hosting, and external services are paid for separately if used.
  • Terms of use: MIT for the code; dependencies have separate licenses.
  • The sync API lacks .mjs/.mts; moduleName must be a valid filename, so a scoped package name cannot be used directly.

Frequently asked questions

What can you use for free in Cosmiconfig?

Code and local use under MIT.

What additional costs might arise with Cosmiconfig?

Computing resources, self-hosting, and external services are paid for separately if used.

What terms of use matter for Cosmiconfig?

MIT for the code; dependencies have separate licenses.

How do you get started with Cosmiconfig?

Define the tool name and supported configuration sources. Connect config discovery and test the processing order of detected settings. Add error handling and an integration check of the result.

How should I choose search, load, and configuration search boundaries?

search searches searchPlaces; load reads a known path; the result includes config/filepath/isEmpty. searchStrategy none checks the current directory, project climbs to package.json, and global climbs to stopDir then the global config directory. Handle parser errors; no config returns null.

License

MIT for the code; dependencies have separate licenses.

MIT — permissive license

You can use, modify, distribute, and sell the code, including in a closed-source commercial product. When sharing copies or substantial portions of the code, retain the license text and copyright notice. You do not need to open-source your entire project; the author provides no warranties.

License terms

Technologies and topics

  • Cosmiconfig
  • API
  • Development

Sources

Other resources