Menu

Post image 1
Post image 2
1 / 2
0

I Built My Own Config Format for Node.js That Separates Server and Client Secrets

DEV Community·KANISHQ R PUROHIT·21 days ago
#u5x9sP8u
#security#node#npm#fullscreen#server#config
Reading 0:00
15s threshold

The problem with dotenv that nobody talks about, and how I fixed it with kq-config. The Problem Every Node.js project I've worked on has the same setup: DB_PASS = supersecret SECRET_KEY = myjwtsecret API_URL = http://localhost:3000 THEME = dark PORT = 3000 Enter fullscreen mode Exit fullscreen mode One .env file. Everything in one place. Server secrets, client settings, database passwords, all mixed together. This works fine until we think: who can see what? Your frontend code runs process.env.API_URL , works fine. But what stops it from also reading process.env.DB_PASS ? In most setups, nothing . The same object holds everything. I kept thinking: why do we give everyone access to everything? The Idea What if your config file had separate blocks: one for the server, one for the client, and each side could only read its own? config.kq ├── ::shared → merged into both ├── ::server → server only └── ::client → client only Enter fullscreen mode Exit fullscreen mode Server reads ::server . Client reads ::client .…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More