My project uses NextJS 13.1.6
I’m having trouble building a url through string concatenation using environment variables.
env.local:
WEBSITE_URL: 'https://somewebsite.com/api/input';
SECRET_KEY: '1234abcd';
src/pages/api/api-requests.js
const response = await fetch(`${process.env.WEBSITE_URL}?secret=${process.env.SECRET_KEY}`)
This url produces this output:
"'https://www.somewebsite.com/api/input';?secret='1234abcd';'"
As you can see there are odd characters in that url string – semi-colons ; and quotes ”
No idea what I’m doing wrong here…
Any help appreciated!
>Solution :
If you .env file look like this
WEBSITE_URL = 'https://www.somewebsite.com/api/input';
remove ; and '' as Scottish Smile commented. Because in .envfile all variables are read as strings, so you don’t need to specify
WEBSITE_URL = https://www.somewebsite.com/api/input