DEV Community

Cover image for env-literal [node.js]
Jorge Arraga
Jorge Arraga

Posted on

env-literal [node.js]

This package iterates the variables of the process.env object, and parses them as if it were a literal javascript string, and injects them back into the same object

For example:

BASE_URL=http://localhost:3000
API=${BASE_URL}/api
Enter fullscreen mode Exit fullscreen mode

In this case, the API variable will have the value http://localhost:3000/api

Unlike dotenv or dotenv-expand, variables are read directly from the system environment and not from an .env file

Usage: as soon as possible, run the function:

const envLiteral = require("@jarraga/env-literal");

if (process.env.NODE_ENV === "production") {
  envLiteral(); // call envLiteral(true) for debugging
}
Enter fullscreen mode Exit fullscreen mode

Link to NPM

Top comments (0)