Reputation: 2094
I've been trying to expand my knowledge of using API keys. I've been able to use a hidden API key with Ruby, now I'm testing out using them in JS. I built a very simple Javascript/jQuery app that uses a API key to tell the weather. I would like to push my code to GitHub. How can I hide this key? Is it as simple as putting the API key in a .gitignore file? Do I need to give any additional commands? This is a simple one page application.
Upvotes: 0
Views: 2537
Reputation: 13896
Put it in a file, lets say you call it config.js
Put the name of that file in your .gitignore
Push to github, check to see if that file is there
It will not be there because that is the purpose of the .gitignore file!
From git docs:
A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.
Link to docs: https://git-scm.com/docs/gitignore
Good Luck!
PS .gitignore files ARE pushed to github see this pic so you don't want to put anything secret in there!
Upvotes: 1