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 🙏

© 2026 – Pkg Stats / Ryan Hefner

env-creator

v1.2.4

Published

A fast, lightweight CLI tool for managing and generating custom environment (`.env`) files

Readme

env-creator

A fast, lightweight CLI tool for managing and generating custom environment (.env) files, designed to simplify development by enabling multiple .env configurations for different environments, as well as automatically generating JavaScript constants for direct use within the project.

Installation

You can install env-creator locally in your project (recommended) or globally.

Local Installation

Install as a development dependency:

npm install env-creator --save-dev
# or
pnpm add -D env-creator
# or
yarn add -D env-creator

Then run it using your package manager's runner:

npx env-creator create
# or
pnpx env-creator create
# or (Yarn Berry)
yarn dlx env-creator create
# or (Yarn Classic)
yarn env-creator create

Global Installation

If you prefer to use it across all projects:

npm install -g env-creator
# or
pnpm add -g env-creator
# or
yarn global add env-creator

Then run it directly:

env-creator create

Usage (examples for pnpm)

env-creator (also available as env) provides several commands (along with their short aliases, e.g. c for create) to help you quickly set up or split your environment files.

Commands:

1. Create an empty or pre-filled .env file (alias: c)

Generates a .env file in the current working directory. You can optionally pass KEY=VALUE pairs to pre-fill it. If a file already exists, it will not overwrite it.

pnpx env-creator create

With initial fields:

pnpx env-creator create PORT=3000 NODE_ENV=development
# or short version
pnpm exec env c PORT=3000 NODE_ENV=development

Resulting .env:

PORT=3000
NODE_ENV=development

2. Create from JSON (alias: cfj)

Generates a .env target file from a provided JSON file. The keys and values in the JSON file will be converted into KEY=VALUE format. You can optionally provide an --env <name> flag to create a specific .env.<name> file (e.g., .env.production).

pnpx env-creator create-from-json <path-to-file.json> [--env <name>]

Example config.json:

{
	"PORT": 3000,
	"DB_HOST": "localhost",
	"NODE_ENV": "development"
}

Command:

pnpx env-creator create-from-json config.json --env production

Resulting .env.production:

PORT=3000
DB_HOST=localhost
NODE_ENV=development

3. Split .env for specific environments (alias: s)

Reads your existing .env file, removes all comments and values, and creates a new target file containing only the keys (e.g., for creating a .env.example or .env.production template).

pnpx env-creator split --env <env-name>

Example: If you have a .env file like this:

# Database Config
DB_USER=admin
DB_PASS=secret

Running the split command for production:

pnpx env-creator split --env production

Will generate a new file named .env.production with empty values:

DB_USER=
DB_PASS=

4. Sort .env keys alphabetically (alias: srt)

Reads an environment file and reorders all KEY=VALUE lines alphabetically. By default, it operates in a flat sort mode, meaning it binds each comment or empty line to the closest variable immediately below it, and sorts these blocks of keys.

If you prefer to strictly preserve the exact file layout and structure, use the --groups (or -g) flag, which performs intra-group sorting that alphabetizes variables tightly inside their original continuous groups. Defaults to .env if no file is specified.

pnpx env-creator sort [--groups] [file]

Examples:

pnpx env-creator sort               		# Flat sorts .env
pnpx env-creator sort -g .env.production	# Group-sorts .env.production

Example 1: Flat Sort (Default)

Before:

DB_USER=admin
DB_PASS=secret
PORT=3000
APP_NAME=my-app

After (env-creator sort):

APP_NAME=my-app
DB_PASS=secret
DB_USER=admin
PORT=3000

Example 2: Intra-Group Sort (--groups)

Before:

# DB Config
DB_USER=admin
DB_PASS=secret

# App
PORT=3000
APP_NAME=my-app

After (env-creator sort -g):

# DB Config
DB_PASS=secret
DB_USER=admin

# App
APP_NAME=my-app
PORT=3000

5. Delete an .env file (alias: d)

Deletes a specific environment file. If no filename is provided, it defaults to deleting .env.

pnpx env-creator delete [file]

Examples:

pnpx env-creator delete				# Deletes .env
pnpx env-creator delete .env.production		# Deletes .env.production

6. Generate environment constants (alias: gc)

Reads an environment file (defaults to .env), extracts the keys, and creates a JavaScript file exporting each key inside a constant object (defaults to envConstants.js). You can specify a custom output file using the --out flag.

pnpx env-creator generate-constants [file] [--out <filename>]

Examples:

pnpm exec env gc					# Generates envConstants.js from .env by default
pnpm exec env gc .env.production			# Generates envConstants.js from .env.production
pnpm exec env gc --out myConfig.js			# Generates myConfig.js from .env
pnpm exec env gc .env.production --out config/env.js	# Generates config/env.js from .env.production

Resulting envConstants.js:

export const ENV = {
	API_URL: process.env.API_URL,
	JWT_SECRET: process.env.JWT_SECRET,
};

[!IMPORTANT] There is no process object in the browser. To use these constants on the client-side, you must inject the environment variables using your bundler.

Example for Webpack (other bundlers like Vite or Rollup will require their own specific configuration):

import webpack from "webpack";
import dotenv from "dotenv";
import path from "path"; // if needed

// load environment variables from .env
const env = dotenv.config().parsed;
// load environment variables from a specific .env file (for example, .env.production)
// const env = dotenv.config({ path: path.resolve(__dirname, `../.env.${envName}`) }).parsed;

// convert to an object for DefinePlugin
const envKeys = Object.keys(env).reduce((acc, key) => {
  acc[`process.env.${key}`] = JSON.stringify(env[key]);
  return acc;
}, {});

// inject variables passing them into DefinePlugin
export default {
  // ...
  plugins: [
    new webpack.DefinePlugin({ ...envKeys }),
  ],
};

Now you can easily import these constants anywhere in your project:

import { ENV } from "[pathToFile]/envConstants";

console.log(`API URL: ${ENV.API_URL}`); // delete after checking

Development

If you want to contribute or modify the tool, you can clone the repository and use the built-in npm scripts:

Linting

To check the code for syntax and style errors using ESLint:

pnpx run lint

Building

The project uses esbuild to bundle and minify the code into a single executable file in the dist/ directory:

pnpx run build

License

This project is licensed under the MIT License - see the LICENSE file for details.