#NextJS app not getting environment variables from Railway

5 messages · Page 1 of 1 (latest)

sick flicker
#

So I have a NextJS app and have set up a environment variable for the API I will be calling (also hosted on railway).

In my component, I am trying to access this environment variable called API_URL as such:

const apiURL = process.env.API_URL
const queryURL = apiURL + '/trips'
console.log(queryURL)

However, in my console on Chrome, it prints: undefined/trips/

How can I properly access env variables on railway?

median rain
#

If you're using a dockerfile, make sure you mention ENV <name>

If you're not, make sure you checkout nextjs' environment variable documentation

#

Please re-open if the above doesn't solve your issue

sick flicker
#

It seems like I wasn't using the NEXT_PUBLIC_ prefix. Thanks!