Search code examples
javascriptnode.jsdotenv

Node.js process.env.YOUR_VARIABLE returning undefined


im trying to hide a discord token for my bot and im pretty sure i have dotenv setup correctly but all i get back is undefined. i even went so far as to use nodemon to restart the server when i make changes and still the same thing.

am i missing something? this is what i have tried so far.

const dotenv = require('dotenv').config();
# and
require('dotenv').config();
var token = process.env.DT;
#and
const token = process.env.DT;
DT=yourtokenhere

Solution

  • I figured it out. my code editor made it seem like it was in the same file as my index.js but it wasn't i feel dumb lol