GithubHelp home page GithubHelp logo

node-utils's Introduction

node-toolbox

Functional utilities for node

  • written in ES6
  • requires node 6 and above
  • Simplifies common routines while setting up a node.js application

isDevEnv


  • reads from process.env and assumes some defaults.
  • Ex.
export NODE_ENV=dev;
const {isDevEnv} = require('node-utils')();
isDevEnv(); // {isDev: true, env: 'dev'};
const {isDev} = require('node-utils')();
isDev(); // true
export NODE_ENV=prod;
const {isDevEnv, isDev} = require('node-utils')();
isDev(); // false
isDevEnv(); // {isDev: false, env: 'prod'};

loadConfig


  • sync - loads a config file from your project directory.
const {loadConfig} = require('node-utils')();
loadConfig();

defaults to:

Project
│
└─── config
     │
     └─── config-dev (.js|.json)

load from an environment variable

export NODE_ENV=qa

loads from:

Project
│
└─── config
     │
     └─── config-qa (.js|.json)

You can optionally specify additional arguments such as directory path, directory name and file name:

loadConfig(__dirname, 'test', 'test-config');

file loads from:

Project
│
└─── src
     │
     └─── test
          │
          └─── test-config (.js | .json)
  1. Note that if you don't specify an extension name the function will default to a .json file format.
  2. You can require the module in one of two flavours
    const {loadConfig} = require('node-utils')()
    or
    const {loadConfig} = require('node-utils')(__dirname);
    The former allows you to specify a path individually per function call or bind a path to all subsequent calls.

node-utils's People

Contributors

stephenotalora avatar

Watchers

 avatar  avatar

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.