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

jsonbank-env

v1.0.2

Published

Covert Json from cloud to .env files

Downloads

65

Readme

JsonBank Env

Npm | Github

What is it?

A command line tool to Get your env files from the cloud as json.

Save as a JSON file remotely and Load it to your project as ENV.

Menu

Installation

You can use this via npx or install it globally.

npm i jsonbank-env
# or
npx jsonbank-env

Json Syntax

The json file must be an object or an array of objects.

Object

The object syntax env file is generated without empty lines.

{
  "NODE_ENV": "development",
  "PORT": 3000,
  "SSL": null,
  "DB_HOST": "localhost",
  "DB_USER": "root",
  "DB_PASS": "root",
  "DB_NAME": "test"
}

Will generate the following env file:

NODE_ENV="development"
PORT=3000
SSL=
DB_HOST="localhost"
DB_USER="root"
DB_PASS="root"
DB_NAME="test"

Array of objects

The array of objects syntax env file is generated with empty lines between each object.

[
  {
    "NODE_ENV": "development",
    "PORT": 3000,
    "SSL": null
  },
  "Comment: Database Configuration",
  {
    "DB_HOST": "localhost",
    "DB_USER": "root",
    "DB_PASS": "root",
    "DB_NAME": "test"
  }
]

Will generate the following env file:

NODE_ENV="development"
PORT=3000
SSL=

# Comment: Database Configuration
DB_HOST="localhost"
DB_USER="root"
DB_PASS="root"
DB_NAME="test"

Configuration

A jsonbank.env.json Configuration file is required. This is where the public key will be defined.

Create config file.

# Create a config file
npx jsonbank-env init

# Create a config file and force overwrite
npx jsonbank-env init force

# Create a config file from custom factory file
npx jsonbank-env init "path/to/factory/file.json"

# Create a config file from custom factory file and force overwrite
npx jsonbank-env init "path/to/factory/file.json" force

The following file will be created.

{
  public_key: "",
  envs: {
    dev: "project/file.json",
  },
}

Insert your public key in the public_key field.

envs

The envs config is where you define the jsonbank remote url of your json files. Given that

  • Project Name on jsonbank is envs
  • File Path is file.json

your config will look like this:

{
  "public_key": "public_key",
  "envs": {
    "dev": "envs/file.json"
  }
}

Commands

Using the example config file below:

{
  "public_key": "public_key",
  "envs": {
    "dev": "envs/default.json",
    "prod": "envs/prod.json"
  }
}

Load env

# Load env to custom local file
npx jsonbank-env <env> <local_path>

# Load env to custom local file and force overwrite
npx jsonbank-env <env> <local_path> force


# Using the example config above
# The command below will load remote "envs/prod.json" to ".env"
npx jsonbank-env prod .env

Load Remote file

# Load remote file
npx jsonbank-env <remote_path> <local_path>

# Load remote file and force overwrite
npx jsonbank-env <remote_path> <local_path> force

# The command below will load remote "envs/prod.json" to ".env"
npx jsonbank-env envs/prod.json .env

Env to Json

How to convert a env file to a json file? We got you covered. You don't need any initialization or configuration. Just run the following command and you are good to go.

# convert json to env and log to console (.env is the default input file)
npx jsonbank-env json

# convert json to env and log to console (custom input file)
npx jsonbank-env json <env_path>

# convert json to env and save to file (custom input file)
npx jsonbank-env json <env_path> <json_path>