npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

env-to-env

v0.2.0

Published

Include environment variables to be automatically set on start

Downloads

15

Readme

env-to-env

Last Release Version License Build Status Coverage Downloads

Include environment variables to be automatically set on start.

Installation

$ npm install -g env-to-env

Usage

As Command-line Tool

You will need to install env-to-env as a global dependency.

Before deployment, run env-to-env inject --keys [...] with the environment variables you want to deploy as arguments. If running without options, env-to-env inject will parse ENV_TO_ENV environment variable and treat value as a JSON Array with environment variable names. You can also set a JSON Object with key-values to inject. The options --keys expects a string with comma-separated environment variable names.

$ env-to-env inject [options]

For example,

$ env-to-env inject --keys DEBUG,PORT,HOST_IP

With Travis CI

Create a .travis.yml file in your repository and setup env-to-env according to command-line usage.

language: node_js
script:
  - npm test
env:
  global:
    - ENV_TO_ENV=['ENV_KEY_1', 'ENV_KEY_2', '...', 'ENV_KEY_N']
    - ENV_KEY_1='value 1'
    - ENV_KEY_2='value 2'
    # ...
    - ENV_KEY_N='value n'
before_deploy: 
  - npm install -g env-to-env
  - env-to-env
deploy:
  # Your deployment configuration

As Package Dependency

Install env-to-env as a package dependency. Save using --save or --save-dev depending on your needs.

$ npm install env-to-env --save-dev

Require env-to-env dependency

import env2env from 'env-to-env';

/* TO BE WRITTEN */

API

Constructor

You may create your env-to-env instance by passing an array of environment variable names (let's call them keys)

import env2env from 'env-to-env';

const env = env2env(['ENV_KEY_1', 'ENV_KEY_2', /* ..., */ 'ENV_KEY_N']);

or by passing an Object with options.

import env2env from 'env-to-env';

const envOptions = { 
  keys: ['ENV_KEY_1', 'ENV_KEY_2', /* ..., */ 'ENV_KEY_N']
};
const env = env2env(options);

Options

Here is an example that creates an Object with all the options available and their defaults.

const defaultOptions = {

  // The list of environment variable names to include in deployment.
  // E.g. ['ENV_KEY_1', 'ENV_KEY_2', /* ..., */ 'ENV_KEY_N']
  keys : [],

  // The name of the script that will prepare the deployment environment

  setEnvScript: '.env.sh',

  // The name of the script that will call the application startup script.
  startAppScript : '.start.sh',

  // The access point for environment variables object.
  env: process.env


};

Methods

This is a list of all public methods of an env-to-env instance.

env2env.object()

Returns an object with all the environment information to be transferred.

This object has environment variable names as keys and strings as values.

Example:

{
  'ENV_KEY_1' : 'value 1',
  'ENV_KEY_2' : 'value 2',
  /* ... */
  'ENV_KEY_N' : 'value N'
}

env2env.json()

Returns a String with a JSON Object with all the environment information to be transferred.

Is the result of stringifying env2env.object() method output.

Example:

'{ "ENV_KEY_1" : "value 1", "ENV_KEY_2" : "value 2", "ENV_KEY_N" : "value N" }'

env2env.bash()

Returns a String with the bash script to setup environment.

#!/bin/bash
ENV_KEY_1='value 1'
ENV_KEY_2='value 2'
# ...
ENV_KEY_N='value N'

env2env.script()

Returns a String with the bash script to setup environment.

Right now this is just an alias for env2env.bash() but it should become cross-platform in a future.

env2env.inject()

Creates options.setEnvScript and options.startAppScript files and modifies package.json to execute options.startAppScript file as start script.

Questions

If you are having difficulties using env-to-env, please ask a question on Stack Overflow.

Examples

The examples folder has basic and advanced examples.

License

This library is licensed under Apache 2.0. Full license text is available in COPYING.

Contributing

See CONTRIBUTING.