New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

env-lift

Package Overview
Dependencies
Maintainers
2
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env-lift - npm Package Compare versions

Comparing version 0.0.1 to 0.0.2

examples/external-json.js

6

examples/sails-local.js

@@ -1,2 +0,6 @@

module.exports = require('../index').load('sails-app', {
/**
* @fileOverview This is a variation of a SailsJS local.js file that uses env-lift to provide configuration overrides
* from environment variables.
*/
module.exports = require('../index').load('envlift-app', {

@@ -3,0 +7,0 @@ // Your SSL certificate and key, if you want to be able to serve HTTP responses

28

lib/main.js
var E = '',
TRUE = 'true',
FALSE = 'false',
/**

@@ -18,3 +20,3 @@ * Default separator while retrieving values of multi-level keys.

rekey = function (key, separator) {
return key.toUpperCase().replace(/[^a-zA-Z]/g, separator || E);
return key.toUpperCase().replace(/[^A-Z0-9]/g, separator || E);
},

@@ -29,6 +31,18 @@

typecasts = {
'string': global.String,
'number': global.Number,
'undefined': global.String,
'boolean': global.Boolean
'string': String,
'number': Number,
'undefined': String,
'boolean': function (value) {
value = value.trim().toLowerCase();
if (!isNaN(value)) {
return Number(value);
}
if (value === FALSE) {
return false;
}
if (value === TRUE) {
return true;
}
}
},

@@ -70,4 +84,4 @@

if (cast) {
// if environment has a truthy variable, we replace the original value with this.
if (process.env[eKey]) {
// if environment has a defined variable, we replace the original value with this.
if (process.env[eKey] !== undefined) {
_debug && console.log('env-lift: %s =', eKey, cast(process.env[eKey]));

@@ -74,0 +88,0 @@ obj[key] = cast(process.env[eKey]);

{
"name": "env-lift",
"version": "0.0.1",
"version": "0.0.2",
"description": "Simple namespaced environment variable configuration management solution",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -1,11 +0,74 @@

<img src="https://travis-ci.org/postmanlabs/env-lift.svg?branch=master" align="right" />
<img src="https://travis-ci.org/postmanlabs/env-lift.svg?branch=master" alt="Master Build Status" />
# env-lift
> This package is being crafted.
*env-lift* provides a NodeJS module to easily read configurations from environment variables. The module makes it super
easy to abstract configuration loading from environment in an organised and namespaced manner.
## Installing env-lift
The easiest way to install env-lift is from the NPM registry. Switch to your project directory and run the following
command. Once installation completes, refer to the usage guidelines or the examples directory to use it in your project.
```terminal
npm install env-lift --save
```
## Usage
Refer to examples directory
The best way to understand how to use this module is to refer to examples. A couple of them is located within the
/examples directory and here we would elaborate on a few use cases.
### A simple use case where config is stored in an external JSON file
In this use-case, let us assume that you are storing your config in a simple javascript variable. For your production
server, you are possibly modifying the variables and running your application. In reality, the use-case could be that
you are fetching the configuration from a separate JSON file. But for all practical purposes, the example here could be
morphed to meet those scenarios.
__Original Code:__
```javascript
var config = {
port: 80,
environment: 'development',
db: {
host: 'localhost',
user: 'root',
password: ''
}
};
```
__Updated code using env-lift:__
```javascript
var config = require('env-lift').load('my-app', {
port: 80,
environment: 'development',
db: {
host: 'localhost',
user: 'root',
password: ''
}
});
```
At this stage, if you can override the values of the configuration using environment variables.
```terminal
export MY_APP_PORT=8080;
export MY_APP_DB_HOST="example.com";
```
Executing the above terminal exports before running your app would return port as 8080 and also return db host as
_example.com_.
## Some gotchas
- The keys are expected to be all uppercase alphanumeric.
- The first letter of the environment variable cannot be a number.
- If your key has non-alphanumeric characters, they are replaced by underscore character
## Contributing

@@ -12,0 +75,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc