This tutorial shows how to access the secret values you've stored in Replit's Secrets tab inside your project's code.
Note: You need a Replit account and an existing project with at least one secret already set. If you haven't added one yet, see How to Set Environment Variables in Replit first.
- Sign in at replit.com and open your project from the dashboard.
- In your workspace, click New Tab and search for Secrets in the left sidebar (the lock icon).
- In the Secrets tab in the left sidebar, confirm your variable is saved - for example, [Name]_TOKEN.
- Open your project file in the editor. The file name depends on your project type:
- Python: main.py(default) or (project name)_main.py(custom)
- Node.js: index.js(default) or (project name)_index.js(custom)
- In your code, call the environment variable by its key name.
- In Python, use os.environ.get('TOKEN').
- In Node.js, use process.env.TOKEN.
- Run your project to confirm it reads the value correctly - for example, your Telegram or Discord bot should connect and come online using the stored token.
.gif)
