Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

env-create

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

env-create

Read in a .env.json file that contains valid JSON and assign top level properties to environment variables

  • 1.1.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
17
decreased by-83.81%
Maintainers
1
Weekly downloads
 
Created
Source

env-create

Reads in a valid JSON file and creates environment variables for every top level object found in the resulting object, unless an environment variable of that name already exists. It will not overwrite existing environment variables. It will only create environment variables for the top level objects.

NPM version BuildStatus Maintainability Test Coverage Inline docs

Installation

npm i env-create --save
Although at this point you should have made --save your default

Basic usage

Let's assume you have a .env.json at the root level of your project with the following contents

{
  "secret1": {
      "client_id": "123445",
  },
  "secret2": {
    "access_token": "reallylongtoken",
  },
}

Somewhere early in your code before you need the environment variables you add

require('env-create').load() 
const firstSecret = JSON.parse(process.env.secret1);
const secondSecret = JSON.parse(process.env.secret2);

The load() method will create a process environment variable for every top level object in the the default .env.json file located at the root of your project. The load() method optionally takes a JSON object with properties for path, and encoding. Both properties are optional. The function returns an array of messages. If an environment variable already existed and would have been overwritten there were will be a message letting you know that.

Option usage

Using a relative path to go up one folder out of your project and into an ENV_VARS folder to get the file named gsweet.env.json

require('env-create').load({
    path: "../ENV_VARS/gsweet.env.json", 
    encode: "utf8"))  
const firstSecret = JSON.parse(process.env.secret1);
const secondSecret = JSON.parse(process.env.secret2);

You can also use an absolute path which is likely preferred if you store authentication data that is required among multiple projects

const result = require('env-create').load({
  path: "/User/yourUserName/ENV_VARS/gsweet.env.json",
  encode: "utf8"))

Acknowledgement

Inspired by dotenv

Keywords

FAQs

Package last updated on 09 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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