Next.js Discord

Discord Forum

Should I hide API key if it's a free service from Internet?

Answered
Red-breasted Merganser posted this in #help-forum
Open in Discord
Red-breasted MerganserOP
I get an free development plan API key from https://newsapi.org/, And I want to use it in my Next.js project. Should I hide the key or it's okay to expose it? Is there any feature for me to hide it in Next.js?
Any idea? Thanks in advance!
Answered by not-milo.tsx
It might be free but you have a limit of 100 requests per day, so yeah you should keep it private in order to avoid someone getting a hold of it and exhausting your daily limit.
View full answer

5 Replies

It might be free but you have a limit of 100 requests per day, so yeah you should keep it private in order to avoid someone getting a hold of it and exhausting your daily limit.
Answer
In Next.js any environment variable prefixed with NEXT_PUBLIC_ is exposed to the client. So by default all your variables are kept on the server until you explicitly tell Next that you want to expose them.
Red-breasted MerganserOP
Wow thanks Milo! So that means I don't have to hide my api key!! So cool!
Next.js does a lot of cool little things to keep us safe from ourselves ahaha
Giant Angora
Yes