acfg
TypeScript icon, indicating that this package has built-in type declarations

1.2.4 • Public • Published

ACFG

Manage your configuration files and keep them up to date.

ACFG detects missing configuration keys and creates them from the given default config. It can also detect live changes in the config file.

Usage

Install the package first

npm i acfg

Add it to your project

import acfg from "acfg";

// Create a new config
// The configuration file gets stored in ./config.json by default
const Config = acfg({
  // Default fields go here
  HTTP_PORT: 8080,
  MONGODB_URI: "mongodb://localhost:27017",
});

mongoose.connect(Config.MONGODB_URI);
app.listen(Config.HTTP_PORT);

// Optional: export it to use it in other files
export default Config;

Alternatively, you can define another path for the configuration file:

import { resolve as r } from "path";
const Config = acfg({
  // Default fields go here
  HTTP_PORT: 8080,
  MONGODB_URI: "mongodb://localhost:27017",
}, {
    path: r(__dirname, "config.json"),
    logMissing: true // Log when ACFG finds and fixes a missing field
});

Package Sidebar

Install

npm i acfg

Weekly Downloads

3

Version

1.2.4

License

ISC

Unpacked Size

7.75 kB

Total Files

4

Last publish

Collaborators

  • memetrollsxd