Protecting Your Twitter API Keys in Node.js with gitignore

If you need to push your code to github for a node.js app that uses the Twitter API, here are the steps that you can take to protect your keys, by using gitignore.

  • Create a separate file that stores your api keys, let’s call it twitterKeys.js

twitter credentials img

  • Require the twitterKeys.js files in the file that you wish to extract data required using the API.
var keys = require('./server/twitterKeys');
  • Now that you ‘required’ the file that contains your Twitter API credentials, you can access them as properties of the keys variable you created above.

twitter credentials img

  • Be sure to add your file that contains your personal information to the gitignore file, before you push your code to GitHub.

Comments