Show More
Commit Commit message Age Author Refs
r25:7b0ae53ffc3d
Fixed a grave mistake
0
r24:988d1dd78689
Updated deps, formatting, versioning, and README
0
r23:36dcfb4f324b
1.3.0
ポール ウェッブ
0
r22:555baba9351f
forEach is better
ポール ウェッブ
0
r21:6f64465d217a
1.2.6
ポール ウェッブ
0
r20:810f0c10b4c9
Updated license
ポール ウェッブ
0
r19:0adecc21a09f
1.2.5
ポール ウェッブ
0
r18:6c7ace8c32ca
Updated deps and updated husky script
ポール ウェッブ
0
r17:597c68c6af95
Updated deps
ポール ウェッブ
0
r16:a49cb6b3cae7
Updated deps
ポール ウェッブ
0
< 1 2 3 >

vne

WebbHub

A clever .env

vne now supports the typed variable syntax of env-smart!

Installation

$ npm i vne

Usage

import env from "vne"; // ES6
// const env = require("vne"); // ES5

console.log(env); // your .env file as an Object

Example

Take this sample .env file:

tokens1="jumble-of-numbers-and-letters"
tokens2="letters-and-jumble-of-numbers"

portDatabase=55555
serviceApi="jumble-of-letters-and-numbers"

dev-api="http://localhost:3000"
prod-api="https://api.domain.tld"

dev-app="http://localhost:3001"
prod-app="https://app.domain.tld"

dev-marketing="http://localhost:3002"
prod-marketing="https://domain.tld"

vne takes the .env file and produces an object like this:

{
  tokens: [
    "jumble-of-numbers-and-letters",
    "letters-and-jumble-of-numbers"
  ],
  portDatabase: "55555",
  serviceApi: "jumble-of-letters-and-numbers",
  dev: {
    api: "http://localhost:3000",
    app: "http://localhost:3001",
    marketing: "http://localhost:3002"
  },
  prod: {
    api: "https://api.domain.tld",
    app: "https://app.domain.tld",
    marketing: "https://domain.tld"
  }
}

Variables with names differentiated by numbers are intelligently placed into an array for easy iteration. A use case would be a handful of tokens you want to have admin access to your API.

Other variables in your .env file with a - or . gets placed into a nested object for easy querying. That way, you will be able to do something like this (check the url parameter):

return new Promise((resolve, reject) => {
  request({
    body: {},
    json: true,
    method: "POST",
    url: process.env.NODE_ENV === "development" ? // BOOM
      env.dev.api :
      env.prod.api
  }).then(body => {
    if (!body)
      return reject(body);

    resolve(body);
  }).catch(error => {
    resolve(error);
  });
});

That one-liner checks to see if your app is running in a development environment or not (of course, this assumes that you are setting your environment when starting your app). Check out the scripts section of this package.json file for reference.

Anyhoo, if your app is running in development mode the parameter on the left side of the : will be called. If not (it's running in production mode), the parameter on the right side is called.

Easy-peasy!