cosmiconfig
npmv10.0.1TypeScriptFind and load configuration from a package.json property, rc file, TypeScript module, and more!
Safe to adopt
Yes — cosmiconfig scores well across adoption, maintenance, weight, supply chain, and licensing. 115.3M downloads per week and 3 known dependents. Last published 10 days ago. 5 releases in the last 2 years.
- AAdoption: grade A, Excellent.
115.3M downloads per week and 3 known dependents.
- AMaintenance: grade A, Excellent.
Last published 10 days ago. 5 releases in the last 2 years.
- AWeight: grade A, Excellent.
Pulls in 3 transitive packages, about 92 KB installed (at least — some of the tree is still being crawled).
- ASupply chain: grade A, Excellent.
No install scripts, 2 maintainers, and a contained dependency surface.
- ALicense: grade A, Excellent.
MIT — permissive, with no copyleft found in the dependency tree.
Grades are computed deterministically from registry metadata collected by PackageGraph — downloads, dependents, publish dates, the resolved dependency tree, maintainer count, and declared licenses. No third-party scores are used.
Install cost
What you actually take on by adding cosmiconfig to a project.
Runtime packages this one declares itself.
Distinct packages in the full runtime tree, deduplicated the way a package manager would.
Unpacked size of this package plus its entire runtime tree.
Longest resolved dependency chain below this package.
Part of this dependency tree has not been crawled yet, so these figures are a lower bound rather than a final total.
Licenses in the dependency tree
Every license you inherit by installing cosmiconfig, not just its own. Check this before a legal review, not after.
Compatibility
- Node.js
- node ^22.18 || >= 24
- Module format
- CommonJS only
- TypeScript
- Types included
- Install scripts
- None
Quick start
A usage example from the cosmiconfig README.
const { cosmiconfig, cosmiconfigSync } = require('cosmiconfig');
// ...
const explorer = cosmiconfig(moduleName);
// Search for a configuration by walking up directories.
// See documentation for search, below.
explorer.search()
.then((result) => {
// result.config is the parsed configuration object.
// result.filepath is the path to the config file that was found.
// result.isEmpty is true if there was nothing to parse in the config file.
})
.catch((error) => {
// Do something constructive.cosmiconfig vs the alternatives
Packages solving a similar problem in the npm ecosystem, compared on the signals that drive an adoption decision.
| Package | Weekly downloads | Dependents | License | Last release |
|---|---|---|---|---|
| cosmiconfigthis page | 115.3M | 3 | MIT | 10 days ago |
| getenv | 0 | 7 | MIT | 1 day ago |
| strip-json-comments | 0 | 2 | MIT | 1 day ago |
| loose-envify | 65M | 2 | MIT | 1 day ago |
| @react-native/metro-config | 4.4M | 6 | MIT | 1 day ago |
| defaults | 0 | 1 | MIT | 1 day ago |
Dependencies
Declared by cosmiconfig v10.0.1. Runtime dependencies are installed with the package; dev dependencies are not.
Runtime (2)
Dev (19)
Used by
Popular packages that depend on cosmiconfig.
Leaner CSS
This package is part of the [React Native CLI](../../README.md). It contains commands for managing the configuration of React Native app.
Core config loading and inspection utilities for Oxlint Config Inspector.
Relationship graph
Dependencies (left) and dependents (right) of cosmiconfig.
Frequently installed together
TypeScript definitions for node
An AST-based pattern checker for JavaScript.
A comprehensive library for mime-type mapping
Packs ECMAScript/CommonJs/AMD modules for the browser. Allows you to split your codebase into multiple bundles, which can be loaded on demand. Supports loaders to preprocess files, i.e. json, jsx, es7, css, less, ... and your custom stuff.
Generates and consumes source maps
An optimised way to copy'ing an object. A small and simple integration
Turn node's process.version into something useful.
BDD/TDD assertion library for node.js and the browser. Test framework agnostic.
A drop-in replacement for fs, making various improvements.
the most correct and second fastest glob implementation in JavaScript
A high-level API to automate web browsers
Display differences clearly so people can review changes confidently.
Release history
5 releases in the last two years, typically about 5 days apart.
| Version | Published | Size | License |
|---|---|---|---|
| 10.0.1latest | 10 days ago | 77 KB | MIT |
| 10.0.0 | 1 month ago | 77 KB | MIT |
| 10.0.0-alpha.0 | 3 months ago | 71 KB | MIT |
| 9.0.2 | 3 months ago | 75 KB | MIT |
| 9.0.1 | 6 months ago | 80 KB | MIT |
| 9.0.0 | 2 years ago | 121 KB | MIT |
| 9.0.0-alpha.3 | 2 years ago | 106 KB | MIT |
| 9.0.0-alpha.2 | 2 years ago | 104 KB | MIT |
| 9.0.0-alpha.1 | 2 years ago | 117 KB | MIT |
| 9.0.0-alpha.0 | 2 years ago | 117 KB | MIT |
| 8.3.6 | 3 years ago | 77 KB | MIT |
| 8.3.5 | 3 years ago | 76 KB | MIT |
| 8.3.4 | 3 years ago | 76 KB | MIT |
| 8.3.3 | 3 years ago | 76 KB | MIT |
| 8.3.2 | 3 years ago | 76 KB | MIT |
Overview
cosmiconfig is an npm package that find and load configuration from a package.json property, rc file, TypeScript module, and more!. It is extremely widely used, with about 115.3M downloads per week and 3 known dependents in the graph. The latest version is 10.0.1, released under the MIT license.
Who should use it
Teams working in the npm ecosystem who need find and load configuration from a package.json property, rc file, TypeScript module, and more! and value a battle-tested, widely-adopted solution.
When not to use it
Consider an alternative if you need to minimize your dependency tree, or if a more actively-maintained option better fits your npm stack.
Pros
- Large, well-established user base (115.3M weekly downloads).
- Ships TypeScript type definitions.
- Clear open-source license (MIT).
Cons
- Large dependency tree (21 direct dependencies) increases install size and audit surface.
Auto-generated from collected registry metadata. No external claims are inferred.
Maintainers
Keywords
Funding
Frequently asked questions
Should I use cosmiconfig?
Yes — cosmiconfig scores well across adoption, maintenance, weight, supply chain, and licensing. 115.3M downloads per week and 3 known dependents. Last published 10 days ago. 5 releases in the last 2 years.
How do I install cosmiconfig?
Run `npm install cosmiconfig` to add cosmiconfig to your npm project.
How many dependencies does cosmiconfig have?
cosmiconfig declares 21 direct dependencies and pulls in 3 packages in total once its runtime tree is resolved totalling about 92 KB on disk.
What license is cosmiconfig released under?
cosmiconfig is distributed under the MIT license.
How popular is cosmiconfig?
cosmiconfig has approximately 115,311,385 downloads per week and 3 known dependent packages.
Is cosmiconfig still maintained?
The most recent release of cosmiconfig (v10.0.1) was published 10 days ago.
Does cosmiconfig run install scripts?
No. cosmiconfig does not define preinstall, install, or postinstall scripts, so installing it does not execute publisher-supplied code.