Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

John Reardon
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
John Reardon
Front End Web Development Techdegree Graduate 16,916 Points

Encrypting API Keys for GitHub

I have been searching for a solution to this. I have a side project I would like to publish to GitHub so I can display it on my portfolio. The project uses data from two third party APIs and I have private API keys/access tokens assigned to my accounts. I am looking for a means to encrypt my API keys/access tokens so I can publish my project to GitHub safely. Any ideas?

The easiest option I can think of would be to set up a GitHub subscription and set the repo to private. I don't really need people to view the source code but I do need to set up a GitHub project page so the site can be viewed live. However, this is going to cost money and I would like to find a free solution if possible. If there is a workaround that anyone knows I would appreciate it.

2 Answers

Thomas Nilsen
Thomas Nilsen
14,957 Points

A common way to hide you private keys and such is to use a NPM-package called dotenv.

You store everything in an .env file which you then add to the .gitignore so it doesn't get uploaded to GitHub.

This is exactly what I would do!

Thomas Nilsen
Thomas Nilsen
14,957 Points

Here is a project that I haven't worked on in a while.

That should make how things work pretty clear.