How to import secrets to config.json file

**Question: I have a secret that i want to import to my config.js file. **

Repl link/Link to where the bug appears: https://replit.com/@GhostCrafter101/ghostbot2

 "TOKEN": process.env['token'], 

i have tried importing it this way but it doesnt work

1 Like

Create a .env file in your Replit project. This file should be in the same directory as your config.js file. In the .env file, define your secret token as an environment variable. For example:

token=your_secret_token_here

Save the .env file. In your config.js file, you can use the dotenv library to load the environment variables from the .env file. Make sure you have dotenv installed in your Replit project.

require('dotenv').config(); // Load environment variables from the .env file

module.exports = {
  TOKEN: process.env.token, // Access the token as an environment variable
  // Other configuration options...
};

Ensure that the require('dotenv').config(); line is at the top of your config.js file. Now, you can access the TOKEN variable in your code as process.env.token, and it will contain the secret token you defined in the .env file.

im sorry i made a typing mistake. I want to import the replit secret to config.json file , not config.js. you can check my repl: https://replit.com/@GhostCrafter101/ghostbot2