How to hide an API code

Hi there!

I was wondering if there is a way to hide API codes in JavaScript files.
I would like to use some projects to show off on my portfolio website. However, some are with API codes. To this day i haven’t really found a way to hide my API codes (such as accu weather, spotify…).


Thanks in advance!


The most common way is to use an environment variable, you create a special .ENV file to store keys (which you keep locally and do not share/push) and then use a module like dotenv to process them:

Also depending on how you are hosting the project, most hosting providers (i.e Heroku) have the ability to add and securely access keys and the like but that will vary depending on where the project is running.

Happy coding! :slightly_smiling_face:



Cheers! I’ll be testing that soon!

1 Like

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