Open pixeljellyfish opened 4 years ago
Did you restart your computer after after adding the environment variables? If you print the CLIENT_ID in your code I think you will find that the variables don't exist yet until restart. Hope this helps
Alternatively, you can set environment variables at runtime. This way doesn't need restarting computer, but instead needs to be set every time.
On Windows: set CLIENT_ID=id&& set CLIENT_SECRET=secret&& node server.js
Or Mac/Linux: CLIENT_ID=id CLIENT_SECRET=secret node server.js
i did restart my comptuer and where would i place the runtime variables
Just replace id
with your client id and secret
with your client secret
Let's say your client id is 000000000000000000
and your client secret id aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
, you can run this command:
On Windows: set CLIENT_ID=000000000000000000&& set CLIENT_SECRET=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa&& node server.js
Or Mac/Linux: CLIENT_ID=000000000000000000 CLIENT_SECRET=aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa node server.js
oh okay thanks
This worked for me but needed a restart.
thats what i did and it doesn't work for me
create a .env file and install 'dotenv' as package (npm i dotenv) and write in you main file
require('dotenv').config()
in the .env you can store variables, and if you upload it to a github don't forget to add the .env in the .gitignore
.env file conten be like: CLIENT_ID=YOUSUPERSECRETCLIENTID CLIENT_SECRET=YOUSUPERSECRETTOKEN
ok thank you
i get this error when i go to press login but i the same discord.js
"Value \"undefined\" is not snowflake."
and this is the code const express = require('express');
const router = express.Router();
const CLIENT_ID = process.env.CLIENT_ID; const CLIENT_SECRET = process.env.CLIENT_SECRET; const redirect = encodeURIComponent('http://localhost:50451/api/discord/callback');
router.get('/login', (req, res) => { res.redirect(
https://discordapp.com/api/oauth2/authorize?client_id=$%7BCLIENT_ID%7D&redirect_uri=http%3A%2F%2Flocalhost%2Fapi%2Fdiscord%26callback&response_type=code&scope=identify
); });module.exports = router;