Skip to content

thesyedbasim/jsenv

Repository files navigation

JSON to Env variables

This package converts your JSON file to environment variable format. This executable also provides process.env.<key> for you to copy in your code.

Installation

npm install -g @syedbasim/jsenv

Usage Syntax

jsenv <input file> <output file> -w -p <?prefix>

Note: -w (write) and -p <prefix> (prefix) are optional. See Prefix and Append & Write modes for more detail.

Example

file.json

{
	"port": 8000,
	"projectName": "json-to-env-var"
}

In Terminal:

jsenv file.json .env

Will output in .env file:

PORT=8000
PROJECT_NAME="json-to-env-var"

Also, the terminal will generate code which you can copy and paste in your JS/TS files:

{
        port: process.env.PUBLIC_VAR_PORT,
        projectName: process.env.PUBLIC_VAR_PROJECT_NAME
}

Passing a prefix

jsenv file.json .env -p public_var

Will output to:

PUBLIC_VAR_PORT=8000
PUBLIC_VAR_PROJECT_NAME="json-to-env-var"

Append & Write mode

By default, this executable will append to the output file. If you want to write to it (i.e. remove any existing data in the output file and then writing), you can specify -w flag.

jsenv file.json .env -w
jsenv file.json .env -w -p prefix

About

A package that converts your JSON file to environment variable format.

Resources

License

Stars

Watchers

Forks

Packages

No packages published