# Where to store API keys? \[Solved\]

**URL:** <https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753>\
**Category:** I Built This\
**Created:** [August 5, 2016, 9:41pm UTC](https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753 "2016-08-05T21:41:34Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Neotriz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/neotriz/32/22474_2.png) [@Neotriz](https://forum.freecodecamp.org/u/Neotriz)\
**Post date:** [August 5, 2016, 9:41pm UTC](https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753/1 "2016-08-05T21:41:35Z")

</div>

Hello all  
I decided to use Bing’s API Image Search since it’s pretty straightforward.

That being said, it requires to use an API Key.

I’ve read that it’s not recommended to store the API key on the client side (which make sense since API keys is something we keep it hidden from the public).

So would it make sense to simply store the API key in a variable within your server file (lets say I am running server.js that runs node js express)?

---

<div class="post-metadata">

**Author:** ![JacksonBates](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/jacksonbates/32/123402_2.png) [@JacksonBates](https://forum.freecodecamp.org/u/JacksonBates)\
**Post date:** [August 5, 2016, 9:50pm UTC](https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753/2 "2016-08-05T21:50:15Z")

</div>

There is some relevant discussion and tips here:

> **[Here is my URL Shortener Microservice](https://forum.freecodecamp.org/t/here-is-my-url-shortener-microservice/21302)**
>
> Hi everyone! Had a lot to learn for this one, but just managed to finish my URL Shortener: https://url-shortener-88digital.herokuapp.com/ It works I think and it’s a first attempt, but I need to refactor the code. Any feedback welcome, thanks!...

---

<div class="post-metadata">

**Author:** ![jemagee](https://avatars.discourse-cdn.com/v4/letter/j/ecc23a/32.png) [@jemagee](https://forum.freecodecamp.org/u/jemagee)\
**Post date:** [August 5, 2016, 9:54pm UTC](https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753/3 "2016-08-05T21:54:00Z")

</div>

If you go into serious hosting and such you should store your API keys as environment variables on your server which yoru applications should be able to access

Same with any database passwords and the like

---

<div class="post-metadata">

**Author:** ![Neotriz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/neotriz/32/22474_2.png) [@Neotriz](https://forum.freecodecamp.org/u/Neotriz)\
**Post date:** [August 5, 2016, 10:06pm UTC](https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753/4 "2016-08-05T22:06:01Z")

</div>

Awesome guys, just what I was looking for  
Thanks guys!

---

<div class="post-metadata">

**Author:** ![chuckadams](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/chuckadams/32/109651_2.png) [@chuckadams](https://forum.freecodecamp.org/u/chuckadams)\
**Post date:** [August 7, 2016, 3:29pm UTC](https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753/5 "2016-08-07T15:29:21Z")

</div>

Typically, you store your API keys and database passwords and other sensitive info in a config file on the backend that’s only readable to the owner of the app. You don’t store that config file in git however – you store a sample version of it instead, containing dummy keys. You then create the real config when you deploy the app to your server, which is done either by hand for a small site, or with devops tools like Puppet or Chef if you’re deploying to multiple (think dozens to hundreds) of servers.

Ideally, don’t even use database passwords at all, and set up your database to use host-based and public key auth instead. You still have to guard the private key file the same as a password, but at least passwords aren’t getting sent around.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 6:10pm UTC](https://forum.freecodecamp.org/t/where-to-store-api-keys-solved/25753/6 "2021-06-01T18:10:00Z")

</div>

Closed on June 1, 2021, 6:10pm UTC


