DEV Community

Jesse Warden
Jesse Warden

Posted on • Originally published at jessewarden.com

1

Node.js' config Library Shouldn't Be Used in TypeScript

Coming back to typed 100% AWS Lambda API’s, I’m convinced the config module is an anti-pattern if you’re using TypeScript.

Been away from typed server-side for about 4 years. While the 1st I had ReScript on the back-end in Amplify, the rest of the companies I was at did JavaScript/Python. In those languages, dynamic, sleek, easy to use global variables are nice for smaller projects with quick deploys.

Like types? Nope; all the allure dynamic languages have for ā€œuse a global proces.env.NODE_ENV to grab some dev.json that is magically inherited from default.jsonā€ suddenly screams ā€œWhy is this all un-typed, un-parsed without Zod, not wrapped in a Result, and why is config not used via dependency injection? Globals… in 2025?ā€

Then you realize… you don’t even need anything beyond some simple types + 1 helper function, and you’ve got a type safe, environment aware configuration.

First define your default config, equivalent to config’s ā€œdefault.jsonā€.

Second, define your dev and prod config, extending the default (both in types and in values).

Finally, create a get method, passing in process so you can unit test it with a stub vs. using it as a global variable. An improvement would be to pre-parse NODE_ENV so you don’t need a default in the switch.

JavaScript, I’m fine with the config module. In TypeScript, it’s dangerous and shouldn’t be used in Node.js.

AI-Assisted Feature Flags and Experiments

How We Turned a Hackathon Idea Into a Production-Ready MCP Server

See how DevCycle turned a hackathon project into a game-changing feature flag MCP server for AI coding agents.

Learn More

Top comments (1)

Learn How Clay Overcame Web Scraping Barriers

Learn How Clay Overcame Web Scraping Barriers

Clay helps customers enrich their sales pipeline with data from even the most protected sites. Discover how Clay overcame initial limitations and scaled past data extraction bottlenecks with a boost from ZenRows.

Read More

šŸ‘‹ Kindness is contagious

Explore this insightful write-up, celebrated by our thriving DEV Community. Developers everywhere are invited to contribute and elevate our shared expertise.

A simple "thank you" can brighten someone’s day—leave your appreciation in the comments!

On DEV, knowledge-sharing fuels our progress and strengthens our community ties. Found this useful? A quick thank you to the author makes all the difference.

Okay