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 🙏

© 2025 – Pkg Stats / Ryan Hefner

nextjs-env-injector

v1.0.2

Published

Inject runtime environment variables in your Next.js client app

Readme

🚀 nextjs-env-injector

💡 Inject runtime environment variables into your Next.js appwithout rebuilding!
Perfect for Docker, Amplify, Vercel, or any platform where runtime configs are dynamic.


🔥 Why nextjs-env-injector?

✅ Load config at runtime — no rebuild required
✅ Compatible with Next.js App Router and Pages Router
✅ Fully typed hook support for useRuntimeEnv()
✅ Supports fallback UI during async config load
✅ Ideal for CI/CD and multi-environment deployments

🧠 "Stop hardcoding, start injecting."


📦 Installation

npm install nextjs-env-injector

🛠 How It Works

At runtime, it fetches a JSON config from /public/env-config.json
and makes it available via:

  • window.env
  • useRuntimeEnv() hook

No environment variable is bundled — just runtime injected 🪄


🧪 Usage

1️⃣ Create public/env-config.json

{
  "API_URL": "https://api.example.com",
  "APP_ENV": "production"
}

⚠️ DO NOT put secrets here — it's public.


2️⃣ Inject the runtime config in your layout/app file

App Router (app/layout.tsx) or Pages Router (pages/_app.tsx):

import { InjectRuntimeEnv } from "nextjs-env-injector";

<InjectRuntimeEnv
  envPath="/env-config.json"
  fallback={<div>Loading env...</div>}
/>
  • envPath: (optional) path to JSON config file
  • fallback: (optional) JSX fallback while loading config

3️⃣ Access env values

✅ Via hook (preferred)

import { useRuntimeEnv } from "nextjs-env-injector";

const env = useRuntimeEnv();
console.log(env.API_URL); // "https://api.example.com"

✅ Or via global window.env

console.log(window.env?.API_URL);

🌐 Common Use Cases

| Use Case | Supported ✅ | |------------------------------|--------------| | Docker runtime env injection | ✅ | | Amplify or Vercel configs | ✅ | | Multi-tenant deployments | ✅ | | Secrets management | ❌ (Don't use for secrets!) |


🧑‍💻 Dev Tips

  • You can generate env-config.json dynamically in CI/CD or Docker:
echo '{"API_URL": "'"$API_URL"'"}' > public/env-config.json
  • Always wrap your app early with <InjectRuntimeEnv /> to ensure availability before any access.

🛠 Build & Publish (for maintainers)

npm run build
npm publish --access public

📜 License

MIT © Hareesh Bhittam


💬 Contribute & Support

If you find this useful, give it a ⭐ and share it!
Open an issue or create a PR for improvements.

Made with ❤️ by Hareesh Bhittam