Heroes Angular Serverless
TypeScript Node/Express
This project was created to help represent a fundamental app written with Node Express APIs and TypeScript that can be shifted to Serverless Functions with TypeScript.
The client app is Angular, however it could just as easily be Vue or React. The heroes and villains theme is used throughout the app.
by John Papa
Comparative client apps written with Vue and React can be found at at github.com/johnpapa/heroes-vue and github.com/johnpapa/heroes-react
Why
I love Node and Express for creating APIs! These require a server and paying for that server in the cloud. Shifting to serverless alleviates the cost, the server upkeep, helps scale up and down easily, and reduces the surface area of the middleware required for a robust Express app. Is it perfect? No, of course not! But this is a solid option if these factors affect you.
Prerequisites
- We need a database. You can use the free Azure Cosmos DB trial. Or try the Azure Free Trial.
- Create an Azure Cosmos DB database.
- Create a container named
heroes
and another namedvillains
. Give each a partition key of/id
. You can add data through the app later. - Make a copy of the
env.example
file named.env
, in the root of the project. It should contain the following code. Replace theCORE_API_KEY
andCORE_API_URL
variables with your Azure Cosmos DB information.
.env
NODE_ENV=development
PORT=7070
WWW="./"
CORE_API_KEY="your-azure-cosmos-db-api-key-goes-here"
CORE_API_URL="https://papa-cosmos-api-db.documents.azure.com/?WT.mc_id=heroesangularserverless-github-jopapa"
Open the /functions/local.settings.json
file and add the CORE_API_KEY
and CORE_API_URL
variables as shown below. Fill those values in with your database information.
/functions/local.settings.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "",
"FUNCTIONS_WORKER_RUNTIME": "node",
"CORE_API_KEY": "your-azure-cosmos-db-api-key-goes-here",
"CORE_API_URL": "https://your-azure-cosmos-db-url-goes-here:443/"
}
}
Getting Started
-
Clone this repository
git clone https://github.com/johnpapa/heroes-angular-serverless.git heroes cd heroes
-
Install the npm packages
npm install
-
Build the Node Express and the Angular code
npm run node-ng:build
-
Run the app
npm run node:start
Debug Node Express and Angular
-
Open
proxy.conf.json
and change the port to7070
-
Open the VS Code Command Palette
F1
-
Type
View: Show Debug
and pressENTER
-
Select
Debug Express and Angular
-
Press
F5
-
Open the browser to http://localhost:7070
You may now set break points in the Express and Angular code.
Debug Functions and Angular
-
Open
proxy.conf.json
and change the port to7071
-
Open the VS Code Command Palette
F1
-
Type
View: Show Debug
and pressENTER
-
Select
Debug Functions and Angular
-
Press
F5
-
Open the browser to http://localhost:7071
You may now set break points in the Functions and Angular code.
Problems or Suggestions
Resources
- Azure Free Trial
- VS Code
- VS Code Extension for Node on Azure
- VS Code Extension Marketplace
- VS Code - macOS keys
- VS Code - Windows keys
- Azure Functions local.settings.json file
- Tutorial to Deploy to Azure Using Azure Functions