How On Earth Do You Use NASA APIs with Azure Functions? 🚀🌍
Tags: javascript, webdev, beginners, tutorial
Published: 2020-03-03 22:56:44

---
title: How On Earth Do You Use NASA APIs with Azure Functions? 🚀🌍
published: true
description: Using Twilio, VSCode, and Azure Functions to create a text thread with you and Earth 🌎🤳
tags: javascript, webdev, beginners, tutorial
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/zvbbfd49o69mu1m3jztf.png
---

*This post ([co-created with Sophia Li](https://twitter.com/sophia_wyl)) will walk you through how to use [Azure Functions](https://docs.microsoft.com/en-us/learn/modules/create-serverless-logic-with-azure-functions/?WT.mc_id=nasafunctions-devto-chcondon), [VSCode](https://visualstudio.microsoft.com/?WT.mc_id=nasafunctions-devto-chcondon), and [Twilio](www.twilio.com/referral/xBBj30) to create a text thread between you and Earth (well, you and the [NASA EPIC API](https://epic.gsfc.nasa.gov/) 🤳).*

*We built this using the Azure portal + VSCode and is intended for students and learners new to Azure. You can of course build this however you'd like! These particular steps have been written for those new to our portal + VSCode (with lots of visuals to help you along the way!).*

*Love this post? Hiring? Sophia is job searching! You can [contact her on Twitter](https://twitter.com/sophia_wyl) or [check out her website](https://sophiali.dev/) if you’re interested in chatting with her (seriously- hire her before someone else snatches her up- she also bakes amazing sourdough bread! 🥖🍞🥯).*

*Happy coding! -💕 Chloe*

*P.S. There's a bit of a preamble here to give context on this project. If you'd like to skip to the code, scroll down to "Let's Get to the Code! 👩🏼‍💻" below!*

![](https://media.giphy.com/media/RgapnV0F0opQ1ERigL/giphy.gif)

Last year, I had the opportunity to experience the launch of [SpaceX CRS-18](https://en.wikipedia.org/wiki/SpaceX_CRS-18) at NASA's [Kennedy Space Center](https://twitter.com/NASAKennedy) as a [NASA Social](https://www.nasa.gov/connect/social/index.html) attendee, and it changed my entire world (errr- universe?) view.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/31iucvtgd70kqk8hc3ha.jpg)

Before my visit to Kennedy Space Center, space (and NASA specifically) felt like something far, far, away- almost untouchable by anyone other than the few and brave astronauts and scientists that made our US launches successful and possible. In elementary school I'd be green with envy over the kid contestants on [Double Dare](https://www.youtube.com/watch?v=XEZCY95JliY) and [Legends of the Hidden Temple](https://youtu.be/WQvzoY9SaQY) who'd [win grand prizes to space camp](https://youtu.be/OVLE124Z-qk) for completing obstacle courses. 🏆


{% youtube WklngEJ7cgs %}
Believe it or not, this was the ultimate in cool for a young child of the 90s, but alas, I attended theatre & horse camp instead...

![](https://media.giphy.com/media/jxbskjmRpRriZthULC/giphy.gif)
...ah, what could have been! 🚀😭


As a theatre kid with ADHD (++ a dash of [dyscalculia](https://twitter.com/ChloeCondon/status/1235615100959985664) to add some fun 🧮), I had always assumed working with NASA was something *completely* unattainable. Unless I could somehow convince my parents to allow me to compete on [Family Double Dare](https://www.youtube.com/watch?v=nbdAaOlZBAc), there was no way I'd ever get close to touching anything space or NASA related. Not to mention the fact I had never seen or heard of anyone who looked/acted/sounded like me doing anything with NASA.

![](https://media.giphy.com/media/BYv467aAFGHHG/giphy.gif)

Until I watched the film [Hidden Figures](https://youtu.be/5wfrDhgUMGI) and learned about [Katherine Johnson](https://barbie.mattel.com/shop/en-us/ba/inspiring-women-series/barbie-inspiring-women-series-katherine-johnson-doll-fjh63), and started following folks like [Bianca](https://twitter.com/PinkRocketship) and [Molly](https://twitter.com/astro_molldoll) on Twitter, NASA (and space related things, for that matter) felt like something men in white lab coats did. And while I *do* own a lab coat (for Dexter's Lab cosplay reasons) I definitely did not see myself or identify with anyone I saw in pop-culture working on space related things.

![](https://media.giphy.com/media/aCCl2Xlkp7VUPG6cud/giphy.gif)
*Except maybe this look from Miss Cracker on season 10 of Rupaul's Drag Race, but I digress...*


Turns out that's far from the truth! **Believe it or not, doing cool things with NASA requires way less math, astronaut training, and eating space food than you think** (although, that space ice cream stuff they have in museum gift shops is pretty tasty! 🍦).

![](https://dev-to-uploads.s3.amazonaws.com/i/w81qg1cnhr9nvvrhdf6b.jpg)

I was lucky enough to once again attend a [NASA Social](https://www.nasa.gov/connect/social/index.html) event- this time, with 2 of my favorite women in STEM: the aforementioned and incredibly talented [Bianca](https://twitter.com/PinkRocketship) and my coworker (+ BFF) [April](https://twitter.com/vogueandcode)! This time, instead of a launch, we visited [Armstrong Flight Research Center](https://twitter.com/NASAArmstrong) in Palmdale California and learned all about the [five new NASA Earth science airborne campaigns](https://www.nasa.gov/feature/goddard/2019/nasa-embarks-on-us-cross-country-expeditions) getting ready to take to the field in 2020! 🌍🛩🌊🛰

For those unfamiliar with NASA, you may be puzzled to hear they would have such a focus on Earth science (vs. the usual coverage of other planets, space travel, etc). However, knowing about our own home planet's behavior and health is just as important as learning what's beyond it! You can learn more about each mission in detail [here](https://www.nasa.gov/feature/goddard/2019/nasa-embarks-on-us-cross-country-expeditions), but here's a brief summary of the 5 missions discussed at this event:


☃️ **Intense Snowfall Events**
*IMPACTS (the Investigation of Microphysics and Precipitation for Atlantic Coast-Threatening Snowstorms), will study how snow is distributed in the clouds. This is the first major field campaign to study East Coast snowstorms in 30 years (and is particularly exciting since the instrumentation on the aircrafts used to test this has madesignificant advancement since then!*


🌡 **Ocean-Atmosphere Heating**
*Ever heard of an "eddie"? Nope, not [this kind](https://www.youtube.com/watch?v=cSmn6kCy1eI). They are circular currents of water that facilitate the exchange of heat between the ocean and the atmosphere and the vertical transport of nutrients, oxygen, and dissolved gases in the upper ocean. Researches using the S-MODE (**S**ub-**M**esoscale Ocean Dynamics Experiment) will make these observations 200 miles off the coast of San Francisco.*


🌊 **River Deltas and Sea Level Rise**
*Coastal deltas act as nurseries for fish, crustaceans and other animals, in addition to protecting our infrastructure against hurricanes and tsunamis. The Delta-X mission will provide scientists with data to better understand sea level rise (most major deltas are sinking under and disappearing) and understand and determine if they can mitigate the impacts of the very important coastal resources the deltas provide.*


☁️ **Aerosols Changing Clouds**
*ACTIVATE (the Aerosol Cloud Meteorology Interactions Over the Western Atlantic Experiment) will measure a broad range of aerosol, cloud and meteorological conditions. Using a NASA Falcon and King Air, researchers will be measuring these conditions, providing them with a more comprehensive measurement to draw definite conclusions about the effects of these interactions.*

⛈ **When Strong Storms Punch into the Stratosphere**
*DCOTSS (or Dynamics and Chemistry of the Summer Stratosphere) will be targeting intense storms to investigate that form over the central US in the Summer months. NASA's ER-2 high-altitude aircraft (that can fly 70,000 feet, significantly higher than most research aircraft can go!) as well as weather satellites and ground-based radar, will help us "learn how these storms affect today's stratosphere, and how their impacts might change as the atmosphere changes in coming decades” according to Ken Bowman, DCOTSS principal investigator from Texas A&M University.*

I learned so many things during my 2 visits to NASA, but by far the biggest takeaway has been this: **NASA is basically the grandfather of space open source™️**. I used to view NASA as a big powerful organization with top secret vaults, men in astronaut suits, and imposing dudes with ear pieces talking about space things in their top secret space offices with their secret space phones. And while sure, there are many classified things and behind the scenes at NASA that we don't (and may never 👽🤫🛸) get to see, a majority of NASA's research, data, and findings are publicly available for all to use.

Which is how this project was born! I met [Sophia](https://twitter.com/sophia_wyl) when she attended our Bootcamp Office Hours at the SF [Microsoft Reactor](https://developer.microsoft.com/en-us/reactor/). We bonded over our non-traditional backgrounds and shared love of bread (blog post involving this coming VERY soon! 🥖🍞). This project was really fun to create together since Sophia was a complete newbie to [Azure Functions](https://docs.microsoft.com/en-us/azure/azure-functions/?WT.mc_id=nasafunctions-devto-chcondon) before this project! We hope you enjoy this project and getting your sea-legs (er- space-legs? 🤔🚀) with [Twilio](www.twilio.com/referral/xBBj30), [Azure](https://docs.microsoft.com/en-us/azure/azure-functions/?WT.mc_id=nasafunctions-devto-chcondon), and the many many open [NASA APIs](https://api.nasa.gov/) available to you!

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/bpoqzwuf029e0xnreeqv.png)

### Let's Get to the Code! 👩🏼‍💻

To follow this tutorial, you’ll need a few things:

#### ☁️ An Azure account
[Azure Functions](https://docs.microsoft.com/en-us/learn/modules/create-serverless-logic-with-azure-functions/?WT.mc_id=nasafunctions-devto-chcondon) make it possible to get projects up and running very quickly, without worrying about spinning up a server. We’ll be triggering our function with an [Azure Functions Timer](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-scheduled-function/?WT.mc_id=nasafunctions-devto-chcondon), but there are many other ways to execute (for other examples, check out other posts on my Dev.to!). If you’ve never worked with Azure before, [this Microsoft Learn tutorial on creating your first function could be helpful](https://docs.microsoft.com/en-us/learn/modules/execute-azure-function-with-triggers/?WT.mc_id=nasafunctions-devto-chcondon), and you can dive into [the docs](https://docs.microsoft.com/en-us/azure/azure-functions/?WT.mc_id=nasafunctions-devto-chcondon) too.

#### ☎️: A Twilio account and phone number


Create a [Twilio account](www.twilio.com/referral/xBBj30), and add a trial phone number that can receive SMS *and* MMS.

This might’ve been obvious, but you’ll also need your cell phone handy for texting/testing your app. 🤳

#### 👩🏼‍💻: VSCode

We'll be using [VSCode](https://visualstudio.microsoft.com/?WT.mc_id=nasafunctions-devto-chcondon) in this tutorial and using its [Azure Functions extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions/?WT.mc_id=nasafunctions-devto-chcondon). Never used [VSCode](https://visualstudio.microsoft.com/?WT.mc_id=nasafunctions-devto-chcondon) before? Totally confused by what an extension is? 🤯😰 Don't worry- [we have docs for that](https://code.visualstudio.com/docs/editor/extension-gallery/?WT.mc_id=nasafunctions-devto-chcondon)! Also, check out the [intro video](https://code.visualstudio.com/docs/introvideos/extend/?WT.mc_id=nasafunctions-devto-chcondon) below.


{% youtube Fed01v3yYNE %}


#### 🛰: A NASA API Key
Head over to the [NASA API website](https://api.nasa.gov/) and generate an API key (keep this handy- we'll need it later to communicate with the Earth!).

We'll be using the EPIC API (Earth Polychromatic Imaging Camera) in our example, but you're welcome to use any [NASA API](https://api.nasa.gov/) you'd like!

![earf](https://media.giphy.com/media/FvKe8DbAMnOda/giphy.gif)

### Prepare to Launch 🚀

Ok- that was a lot of set-up.

![](https://media.giphy.com/media/pCOWKQFdQKUYE/giphy.gif)

Now that we have all the tools we need, let's get to coding!

#### 1️⃣: Create an Azure Function


For the sake of easy to understand visuals/screenshots I used the [Azure portal](https://portal.azure.com/?WT.mc_id=nasafunctions-devto-chcondon) to create this. You can also use [VS Code](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-function-vs-code/?WT.mc_id=nasafunctions-devto-chcondon), the [Azure CLI](https://docs.microsoft.com/en-us/azure/azure-functions/functions-create-first-azure-function-azure-cli/?WT.mc_id=nasafunctions-devto-chcondon), etc.​ With Azure Functions you are given the the ability to code and test Functions locally on your machine without having to deploy to the cloud every single time you want to test (a huge time saver!).

To create an Azure Function, you can just start from the Get Started menu and select Function App in the [Azure portal](https://portal.azure.com/?WT.mc_id=nasafunctions-devto-chcondon).

![](https://thepracticaldev.s3.amazonaws.com/i/gyevy34y36l2py02e2y7.png)

Then you’ll need to fill in some basic info about your function here. Including the app name, the Azure subscription you’d like to use, a [resource group](https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-overview/?WT.mc_id=nasafunctions-devto-chcondon) (I’m creating a new one in this case), the Operating System you’d like to use, the [hosting plan](https://docs.microsoft.com/en-us/azure/azure-functions/functions-scale/?WT.mc_id=nasafunctions-devto-chcondon) (I’m using consumption), the location I’d like to use (I’m in California, so West US 2 is usually my default), the runtime stack I’d like to use (I’m using NodeJS in this case), and I have the option to create new [storage](https://docs.microsoft.com/en-us/azure/storage/common/storage-introduction/?WT.mc_id=nasafunctions-devto-chcondon) or use existing. I created a new one in this case.​​

Click though until you reach the **Review & Create** page, and when you're ready click create!

Now it's time to head over to [VSCode](https://code.visualstudio.com/). Never used VSCode before? No problem! [Here's a great video by Rachel Weil](https://channel9.msdn.com/Blogs/raw-tech/Beginners-Guide-to-VS-Code) to get you up and running in 10 minutes!

Once you have a lay of the land, go ahead and add the Azure Functions [VSCode Extension](https://code.visualstudio.com/docs/editor/extension-gallery/?WT.mc_id=nasafunctions-devto-chcondon).

#### 2️⃣: Add Your Function to VSCode

Once your function is deployed, head over to VSCode and find your function.

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hhn8pxixxnbb6p76yc10.png)


Click the folder icon (as shown above) and create a new file for your project. Then select your language (JavaScript), template (timer trigger), a name for your function (we chose "NASATimerTrigger1"), then enter what time you'd like your timer to go off in the form of a cron expression (we used 0 0 15 * * * to send our texts in the morning, but you'll want to choose this based on your own preference).

Once you've clicked though all of these options, create and open your VSCode project.

In your index.js file, add the following code (don't worry- we'll walk through this in sec!):



{% gist https://gist.github.com/sophi-li/b4f433fdd06129de244613e636a0895f %}


You'll notice we have a couple variables here that have not been defined! We want to keep our Twilio credentials, phone numbers, and API keys safe (and secret!)... lucky for us, there's a simple way to do this in Azure using the portal!

#### 3️⃣: Configure Your Application Settings

Navigate over to **Configuration** and add the following with their values: TWILIO_TOKEN + TWILIO_SID (these can be found on the main page of your Twilio account), SENDER_NUMBER (your Twilio #), RECIPIENT_NUMBER (your number), and your NASA API key (which can be generated [here](https://api.nasa.gov/)). Once you save these, we'll almost be ready for launch! 🚀

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/sqtm9pfiuxanup7i81ml.png)

Stuck? You can check out our docs for more details on using the [Azure Key Vault in the portal](https://docs.microsoft.com/en-us/azure/key-vault/quick-create-portal/?WT.mc_id=nasafunctions-devto-chcondon) as well as [through the Azure CLI](https://docs.microsoft.com/en-us/azure/key-vault/quick-create-cli/?WT.mc_id=nasafunctions-devto-chcondon).

#### 4️⃣: Install a Couple Additional Things

There are a couple additional things we'll need for our app to work. In your VSCode terminal install Twilio with the following command:

```npm install twilio```

And then install node-fetch with the following:

```npm install node-fetch --save```

#### 5️⃣: Deploy from VSCode 

We're almost there! As a final step, let's deploy the work we did in VSCode to Azure!

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/i/hhn8pxixxnbb6p76yc10.png)


Click the deploy button (as shown above- the blue arrow pointing up). You may get some alerts confirming the difference in version here- click through these (we're just confirming our VSCode version differs from the current version in our Azure portal).

If all goes well, and your deployment was successful, it's time to...

#### 5️⃣: Get a Text From Earth!

![](https://media.giphy.com/media/Em61EZtMIwIAo/giphy.gif)

Now it's time to see our Azure Function in action! Click the **Run** button on your Azure Function in the Azure portal to test things out! Your text should look a lil somethin' like this:

![the earf text](https://dev-to-uploads.s3.amazonaws.com/i/bltwoetg900f7gtu9cju.png)

For extra fun, add your Twilio phone # to your contacts, so you know the Earth is hitting up your phone with a selfie each day (errr... is it a selfie if the Earth doesn't have hands so [NASA took it](https://api.nasa.gov/)? 🤔🌎🤳 lol).

#### 6️⃣: Enjoy Your Daily Earth Texts!

If your text sent successfully- congrats! You now will have a daily text from Earth (ok, it's *technically* the NASA API, but we can pretend!).


As always- please reach out with any questions in the comments below ⤵️- Sophia and I are here to help! We look forward to hearing about all the amazing things you build with the NASA API + Azure Functions, and hope you enjoy the daily pics of our beautiful planet ♥️🌎

![](https://media.giphy.com/media/MLt3JGidv2foQ/giphy.gif)