How to import a secret into my config file (node.js)


help! how do i get this to work

  "server": {
    "host": "redacted",
    "port": redacted
  "minecraft": {
    "username": "redacted",
    "password": "redacted",
    "lobbyHolder": "redacted",
    "accountType": "redacted"
  "discord": {
    "token": process.env.token, <<<<<< this line here!
    "channel": "redacted",
    "commandRole": "redacted",
    "ownerId": "redacted",
    "prefix": "!",
    "messageMode": "bot"
  "express": {
    "enabled": false,
    "port": 8880,
    "authorization": "authorizationHeaderString"
1 Like

Hey @DylanK9 welcome to the forums!

Can you post a link to the website? It makes it easier to find the problem if it is somewhere else. This would help for other people to find it since I don’t know anything about node.js sorry.

yea sure! sorry about that

here is the link to the replit, couldn’t figure out how to edit the post haha

sorry but it’s not possible to use env variables in JSON format

is there any way you would recommend then to hide those variables?

Could you explain why? That’d make this answer a lot better.

just use process.env.ENVNAME in the js file

oooooh this is a minecraft bot i own a Minecraft bot but I don’t think that will work I done it once and it kept throwing errors at me

1 Like

that would mess up the rest of the code depending on pulling from the json file then no?

explain what how can i explain that JSON doesn’t support env variables

You could explain why it doesn’t support them, or provide an alternate option for them.
As a note, couldn’t they declare the ENV to a var, then pass the var to the JSON? If not, why?

yeah merging a minecraft bot with a discord wont work I’m pretty sure but I could be wrong

i guess you could call the variable at the top of the page using (const) and call the variable in the rest of the code for example const env = process.env.token then at the place where you need it just use env instead of the process thing

right but as you said this doesnt work in json files

no unfortunately it doesn’t