@dynaconfig/jsonfile
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

@dynaconfig/jsonfile

npm license

A configuration generation library using *.json files.

Usage

'./config.json', before script:

{
  "PASSWORD": "password",
  "HASHED": "false"
}

'./index.js', run script:

// ...
const { async: AsyncJsonStore } = require("@dynaconfig/jsonfile");

// Creates a new instance. 'jsonPath' is the file path
const store = new AsyncJsonStore(jsonPath);

// Every time a new session is created, the store
// loads the configurations from the file
store.newSession().then(async (session) => {
  // Gets the configuration object
  const config = session.getConfig();

  const password = config["PASSWORD"]; // "password"
  config["PASSWORD_HASH"] = md5hash(password);
  config["HASHED"] = "true";
  delete config["PASSWORD"];

  // Writes the new configuration object to the file
  await store.persistSession(session);

  // Reloads the configurations from the file
  await session.refreshConfig();

  // ...

  return;
});

'./config.json', after script:

{
  "HASHED": "true",
  "PASSWORD_HASH": "5f4dcc3b5aa765d61d8327deb882cf99"
}

For more examples, check out @dynaconfig/core.

License

MIT

Readme

Keywords

none

Package Sidebar

Install

npm i @dynaconfig/jsonfile

Weekly Downloads

1

Version

2.0.1

License

MIT

Unpacked Size

27 kB

Total Files

23

Last publish

Collaborators

  • icarus21