🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

envtemp

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

envtemp

A simple template processor that replaces environment variables in files with support for arrays, default values, and special date variables

1.3.2
latest
npm
Version published
Weekly downloads
32
255.56%
Maintainers
1
Weekly downloads
 
Created
Source

envtemp — No Installation, No Mercy

Because your environment variables won't replace themselves.

If you could handle environment templating on your own, you wouldn't be here. But let's not kid ourselves. You're reading this because at some point a ${SECRET} in your config file made a fool of you. It's okay—no, actually it's not—but I'm feeling generous today.

Meet envtemp, the CLI tool that does the one thing you apparently couldn't: replace those damn placeholders with real values. It grabs your environment variables and injects them into your template file like a cold dose of reality. No whining, no hand-holding. And it doesn't even ask you to install it first. envtemp won't judge you; that's my job.

Zero-Install, Zero Excuses

You want to try it, but commitment issues? Figures. With envtemp, you don't need to install anything. Go ahead, run it with npx and watch it appear out of nowhere, do your bidding, and vanish without a trace.

No setup, no global clutter – just one command:

npx envtemp input.template output.file

It executes directly from the npm registry, fresh every time, like a hitman who never sticks around. You have zero excuses left. If Node.js is on your machine (and it better be), you're ready to roll.

How It Works

envtemp is brutally straightforward, which is probably why you didn't think of it:

  • Read: Opens your input template file (the one littered with ${VAR} placeholders).
  • Replace: For each placeholder, it looks up the VAR in your environment:
    • If it's set, envtemp surgically swaps in the value.
    • If it's missing but you provided a default (${VAR:default}), envtemp grudgingly uses that default.
    • If it's missing and you gave no default… you get nothing. The placeholder remains, staring back at you in the output.
  • Write: Dumps the result into the output file you specified, overwriting it without hesitation. (Did you expect a polite confirmation? How cute.)

That's it. No magic, no pity. Just your file, now with actual values instead of fantasies.

Example

Maybe you need a demonstration (of course you do). Suppose you have a template file config.template:

API_URL=${API_URL}
MODE=${MODE:development}

And let's say your environment has API_URL set to https://api.example.com but no MODE variable. Run envtemp:

$ npx envtemp config.template config.txt

After envtemp does its thing, config.txt will contain:

API_URL=https://api.example.com
MODE=development

Array support

Template file (config.toml.template):

keywords = "${KEYWORDS:["seo", "template", "default"]}"
authors = "${AUTHORS:["John Doe", "Jane Smith"]}"
config = {
    tags = ${TAGS:["web", "docs"]}
    ports = ${PORTS:[8080, 3000]}
}

Usage:

KEYWORDS='["react", "node", "typescript"]' PORTS='[3000, 8080, 9000]' npx envtemp config.toml.template config.toml

Notice how it filled in API_URL with the real value from your environment (hope it was the right one), and it quietly used "development" for MODE because you didn't set it. Did you notice how envtemp didn't scream or throw an error? It just did what needed to be done. Efficient – like it should be.

Use Cases

  • CI/CD pipelines: Stop shipping placeholders to production like an amateur. Let your build step npx envtemp your templates so deployments have real credentials and endpoints. No more last-minute oops commits.
  • Docker & ephemeral scripts: Need a config inside a container or a quick one-off file? envtemp generates it on the fly. One command, and your app has the config it craves (then envtemp disappears, as always).
  • Multi-environment configs: One template to rule them all. Keep a single config for dev, staging, prod – envtemp will inject the right values for each environment, so you don't maintain three nearly-identical files (which you would probably mess up).
  • Secret management: Keep sensitive values out of your repo by using placeholders. Your repo stays clean, and envtemp slips the real secrets in only at runtime. It's almost like you planned it.

Features (Cold, Hard Facts)

  • Zero install required: Use it via npx whenever you need. It won't clutter your system or stick around longer than necessary.
  • CLI-only: No importable module, no fancy API. envtemp serves those who live in the command line. If you want an API, write your own (and good luck).
  • Simple syntax: Uses familiar ${VAR} placeholders in text. Supports default values with ${VAR:default} for when you inevitably forget to set something.
  • Cross-platform: Works wherever Node.js works. Windows, Linux, Mac – envtemp doesn't care what OS you're on, or who you are.
  • No mercy on output: The output file will be overwritten without a second thought. If you pointed it at something important, that's on you.
  • Single job, done well: It won't format JSON or validate config files. It finds variables and replaces them. Period. Anything else is your problem.

Final Words

You've made it this far. Now you know exactly what envtemp can do, and exactly which excuses you no longer have. The next time you're tempted to manually fiddle with config placeholders, remember this moment.

Go ahead, walk away if you want. Pretend you don't need envtemp. But when your next deployment goes up in flames because of one stupid missing variable, you'll know where to find it. envtemp will be here, quietly waiting in the dark – ready to help you clean up the mess... if you deserve a second chance.

Consider yourself warned.

Keywords

template

FAQs

Package last updated on 23 Apr 2025

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