.env keys not reading

Hello,

I am having an issue reading the process.env keys from an .env file which stores my twitter api keys.

the code works fine in my localhost but when I upload to render it stops working. I consoled logged the keys and the values appeared in the console but somehow its not reading the keys:

app.listen(port, () => {
console.log(Server listening on port ${process.env.PORT})
console.log(process.env.TWEET_KEY)
console.log(process.env.APP_SECRET)
console.log(process.env.A_TOKEN)
console.log(process.env.A_SECRET)
console.log(process.env.TEST)
;})

When i replace the code with the actual key it works:

const key = process.env.TWEET_KEY

const secret = process.env.APP_SECRET

const atoken = process.env.A_TOKEN

const asecret = process.env.A_SECRET

app.use(express.static(path.join(__dirname, ‘public’)));

const client = new TwitterApi({
appKey: key,
appSecret: secret,
accessToken: atoken,
accessSecret: asecret

});

you have to add ENV variable manually from render hosting panel

Hi,

Secret Files don’t do any magic, or get parsed by the platform, if you create .env file you’ll need something to read it, like a dotenv package.

Or, you can add the environment variable individually, which would make them available to the service environment, as the previous commented suggested.

Alan

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.