How to migrate a traditional Express API to Serverless and save tons of money
Tags: javascript, node, serverless
Published: 2018-06-05 19:21:21

---
title: How to migrate a traditional Express API to Serverless and save tons of money
published: true
description: Building API's on Serverless has both speed and cost benefits. In this video, we look at how to take an existing Mongo DB API running on Express, and move it to a completely Serverless backend.
tags: javascript, node, serverless
---

One of the key tenants of Serverless is that you only pay for what you use. You pay for the bandwidth and compute that is used when your function is called and nothing more. Without serverless, applications just run all the time and, well, it's kinda wasteful. 

You can think of Serverless like this faucet...

![water faucet](https://thepracticaldev.s3.amazonaws.com/i/4e8st62t68ibvwjozv5s.png)

You have water faucets like this one in your house. One way for that faucet to work is for water to just come out all the time. It's always on and whenever you need a drink, you just walk over and fill up your cup. But we don't do that. Why? Because it's wasteful. Instead, we turn the water on when we need it and off when we don't. We only pay for the water we use.

Serverless uses the same concept. Whenever a request is made, the function is loaded into memory and then executed. When the function is not running, it goes dormant and you are not charged for it. This means that it's going to be far cheaper to use Serverless than a traditional application hosting solution.

In this video, I'll walk you through moving an API that's running in a traditional web server model with Express over to Serverless. 

{% youtube 89WXgaY-NqY %}

Here's what we go over in the video...

* [00:19](https://youtu.be/89WXgaY-NqY?t=19s) - Walkthough of existing project (available on [Github](https://github.com/burkeholland/heroes-api))
* [01:27](https://youtu.be/89WXgaY-NqY?t=1m27s) - Create new Serverless project
* [02:26](https://youtu.be/89WXgaY-NqY?t=2m7s) - Create a new HTTP Function
* [02:47](https://youtu.be/89WXgaY-NqY?t=2m47s) - Add a function to read from the database
* [04:16](https://youtu.be/89WXgaY-NqY?t=4m16s) - Testing locally
* [04:47](https://youtu.be/89WXgaY-NqY?t=4m47s) - Create and test the rest of the CRUD functions - Create, Update and Delete
* [07:35](https://youtu.be/89WXgaY-NqY?t=7m35s) - Create a new Functions App in Azure
* [08:35](https://youtu.be/89WXgaY-NqY?t=8m34s) - Deploying code to the Function App in Azure
* [09:20](https://youtu.be/89WXgaY-NqY?t=9m20s) - Add environment variables
* [09:54](https://youtu.be/89WXgaY-NqY?t=9m54s) - Testing deployed Function App with Postman
* [10:28](https://youtu.be/89WXgaY-NqY?t=10m28s) - Using proxies to create RESTful URL's
* [14:30](https://youtu.be/89WXgaY-NqY?t=14m31s) - Pointing the React project at the new endpoint
* [15:23](https://youtu.be/89WXgaY-NqY?t=15m23s) - Enabling CORS

👉 [Download Source From Github](https://github.com/burkeholland/heroes-api)

### Additional Requirements...

* [Azure Account](https://azure.microsoft.com/en-us/free/?WT.mc_id=migratingapi-devto-buhollan)
* [VS Code](https://code.visualstudio.com/?WT.mc_id=migratingapi-devto-buhollan)
* [Azure Functions Extension](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-azurefunctions&WT.mc_id=migratingapi-devto-buhollan)