Skip to content

Instantly share code, notes, and snippets.

@utopianfool
Last active August 27, 2020 20:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utopianfool/ac251e6b0f959eead2d530802d666c03 to your computer and use it in GitHub Desktop.
Save utopianfool/ac251e6b0f959eead2d530802d666c03 to your computer and use it in GitHub Desktop.
Hide API keys from github using Javascript

How to hide API keys from github

Using Javascript

Already pushed commits with sensitive data? https://help.github.com/articles/remove-sensitive-data/

  1. Create a config.js file.

  2. Open config.js and enter your API keys.


var config = {
  mapkey : '12633733456',
  apikey : '56737589'
}

  1. Add a link to the script in your HTML file.

<script type='text/javascript' src='config.js'></script>
<script type='text/javascript' src='script.js></script>

  1. In your main javascript file declare the variables that point to the API keys in config.js.

var myKey = config.mapkey;
var secretKey = config.apikey;

  1. Create a .gitignore file. Note the period at the start of the file name:

.gitignore

  1. In the .gitignore file, enter the names of the files you don't want git to track.

config.js

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment