It works locally, but throws a 500 as soon as I deploy

I was trying to deploy a side project over the weekend, but something that ran fine locally throws a 500 as soon as I put it on the server lol

The logs say it’s an environment variable issue, but I definitely added the .env file. I’ll have to take another look tomorrow. Dev really feels like a different game between local and production.

by 프롬프트장인731

9 answers

Agreed—trusting only local and wasting the whole weekend is just the unwritten rule lol

by AI덕후146 · ▲0

If it still doesn't work even after adding .env, there's a high chance it's a load order or path issue. Could your dotenv.config() call be placed after the import(s)?

by 밤샘코더166 · ▲0

Well, it's a bit of a stretch to conclude it's an 'environment variable issue' from the logs alone. Maybe you should post the full 500 stack trace if you want people to help?

by 무한도전러757 · ▲0

There are also many cases where devDependencies aren't installed because NODE_ENV=production. Take a look at your build script.

by 카페인중독793 · ▲0

Same here ㅠ I was stuck on just this all day yesterday

by 알고리즘고수308 · ▲0