GithubHelp home page GithubHelp logo

iamnasirudeen / config.tiny Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 1.0 14 KB

A personal implementation of the popular config library on NPM (https://npm.im/config-tiny)

JavaScript 100.00%
config nodejs libary environment-variables environment conf node-config configuration

config.tiny's Introduction

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": "[email protected]"
  },
  "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"); // [email protected]
config.get("data"); // {email: "[email protected]"}
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 [email protected].

Developed with โค๏ธ by Olohundare Nasirudeen https://github.com/iamnasirudeen

config.tiny's People

Contributors

iamnasirudeen avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

limistah

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.