Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cosmiconfig

Package Overview
Dependencies
Maintainers
2
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cosmiconfig

Find and load configuration from a package.json property, rc file, TypeScript module, and more!

  • 9.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
60M
decreased by-11.3%
Maintainers
2
Weekly downloads
 
Created

What is cosmiconfig?

The cosmiconfig npm package is a utility for finding and loading configuration from a variety of file formats and locations. It is commonly used in Node.js projects to create flexible configuration systems for tools and libraries.

What are cosmiconfig's main functionalities?

Searching for configuration files

This feature allows you to search for configuration files with a given name in various locations, including package.json properties, rc files, and regular JSON or YAML files.

const cosmiconfig = require('cosmiconfig');
const explorer = cosmiconfig('yourModuleName');
explorer.search()
  .then((result) => {
    const config = result ? result.config : {};
    // do something with config
  })
  .catch((error) => {
    // handle error
  });

Loading configuration files directly

This feature allows you to load a configuration file directly from a specified path, regardless of the file's format.

const cosmiconfig = require('cosmiconfig');
const explorer = cosmiconfig('yourModuleName');
explorer.load('/path/to/config').then((result) => {
  const config = result ? result.config : {};
  // do something with config
}).catch((error) => {
  // handle error
});

Creating a custom explorer

This feature allows you to create a custom explorer with specific search places and loaders, enabling you to define where and how configuration files should be found and interpreted.

const cosmiconfig = require('cosmiconfig');
const explorer = cosmiconfig('yourModuleName', {
  searchPlaces: ['custom.config.js', 'package.json'],
  loaders: {
    '.js': cosmiconfig.loadJs,
    '.json': cosmiconfig.loadJson
  }
});

Other packages similar to cosmiconfig

Keywords

FAQs

Package last updated on 26 Nov 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc