Wondering what’s next for npm?Check out our public roadmap! »

    config-tiny

    1.0.8 • Public • Published

    CONFIG TINY 😊

    A personal implemention of the popular config library on NPM

    Quick Start

    npm i config-tiny

    or

    yarn add config-tiny

    You can also fork the project on github at https://github.com/iamnasirudeen/config.tiny

    Usage

    Create a config folder in the root directory of your project and create a file inside the folder named default.json.

    e.g

    cd `path/to/project/` && mkdir config && cd config && touch default.json

    The code above helps you create a config folder and also a default.json file inside the folder then you can use it like this.

    The content of the default.json file should look like the one below.

    {
      "data": {
        "email": "iamnasirudeen@gmail.com"
      },
      "github_handle": "iamnasirudeen",
      "port": 3000
    }
     

    Then

    const config = require("config-tiny");
    let port = config.get("port") || process.env.PORT;

    You can also check the validity of a string before getting the value using the config.has function. e.g

    const config = require("config-tiny");
     
    // Note: config.has function returns a boolean of true/false
     
    // using ternary operator
    const port = config.has("port") ? config.get("port") : 3000;
     
    // using if statement
    if (config.has("data.email")) {
      // do anything with your value here
      let email = config.get("data.email");
    }

    Note

    The Config folder has to be in the root directory of your project as config uses the nodejs process.cwd() API to locate the root directory of the config folder.

    config.tiny doesnt really support nested objects a future version would have this feature supported.

    e.g

    config.get("data.email"); // iamnasirudeen@gmail.com
    config.get("data"); // {email: "iamnasirudeen@gmail.com"}
    config.get("github_handle"); // iamnasirudeen

    Use Case

    config.tiny can be used to save environment keys. It can be used in replace of DotEnv.

    Contributors are also allowed. You can hit me up at iamnasirudeen@gmail.com.

    Developed with ❤️ by Olohundare Nasirudeen https://github.com/iamnasirudeen

    Install

    npm i config-tiny

    DownloadsWeekly Downloads

    11

    Version

    1.0.8

    License

    MIT

    Unpacked Size

    5.28 kB

    Total Files

    4

    Last publish

    Collaborators

    • avatar