@simona_cotin
Build Nodejs APIs
using Serverless
330m users
6k tweets/s
350k tweets/minute
200b tweets/year
Simona Cotin
Cloud Dev Advocate @
Microsoft
@simona_cotin
@simona_cotin
–Martin Fowler
“Serverless architectures refer to
applications that significantly
depend on third-party services
(known as Backend as a Service
or "BaaS") or on custom code
that's run in ephemeral containers
(Function as a Service or "FaaS")”
Serverless
💡 Reacts to events
💯Autoscales
💰Pay as you go
@simona_cotin
Photo by Uroš Jovičić on Unsplash
Execution time limit
@simona_cotin
Functions are
stateless
@simona_cotin
Warm up time
@simona_cotin
Serverless providers
•Azure Functions
•Amazon Lambda
•Google Cloud Functions
•Auth0 Webtask
•Ibm Openwhisk
Azure Functions
@simona_cotin
✓How do I create a project?
✓How do I debug and run locally?
✓ How do I install npm packages?
✓ How do I connect to a mongodb instance?
✓ Where do I save my env variables?
✓ How to configure REST like URLs?
✓ How do I deploy to the cloud?
@simona_cotin
👷🏼♀️What are we
//WORKER-ing?
@simona_cotin
@simona_cotin
How do I
Create a
Project?
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
How do I
Run & Debug
Locally
@simona_cotin
@simona_cotin
How do I
Install
Dependencies?
@simona_cotin
@simona_cotin
How do I
Connect to
MongoDB?
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
@simona_cotin
How do I
REST
URLs?
@simona_cotin
GET /puppy/{id}
POST /puppy
DELETE /puppy/{id}
PUT /puppy/{id}
@simona_cotin
@simona_cotin
How do I
CORS?
@simona_cotin
How do I
Deploy?
@simona_cotin
@simona_cotin
Because
it’s
awesome!
Why Node.js?
@simona_cotin
•Javascript has a rich
ecosystem of libraries and
tools
•Enable FE developers to
build scalable backends
•Large use base - javascript
is the English of languages
Why Node.js?
@simona_cotin
•Lightweight - helps reduce cold
start
•Commonly run in a distributed,
horizontally scaled fashion
•Scripting means no compilation
required to start from a portal
•Runs equally easy on most
OS’s
Why Node.js?
@simona_cotin
You Can
Sit With
Us ❤️
Why Node.js?
@simona_cotin
How do I create a project?
How do I debug and run locally?
How do I install npm packages?
How do I connect to mongodb?
Where do I save my env variables?
How to configure REST like URLs?
How do I deploy to the cloud?
Why Nodejs?
VS Code & Azure Functions Extension
VS Code & Azure Functions Extension
You know this already :)
You know this already :)
local.settings.json
proxy.json
VS Code & Azure Functions Extension
AWESOME <3
@simona_cotin
Azure Functions
VS Code extension
Azure CosmosDB
Functions Triggers
Artwork
Pluralsight course
https://aka.ms/functions
https://aka.ms/functions-code
https://aka.ms/azure-cosmosdb
https://aka.ms/triggers
https://aka.ms/cda-bit
https://aka.ms/pbp
Resources
@simona_cotin
THANK YOU!

Build Nodejs APIs using Serverless

Editor's Notes

  • #3 I want you to think about twitter for a second. Think about Twitter scale.
  • #4 330 million users in total, 6k tweets/second, 350k tweets
  • #5 Now I want you to think about what if the twitter creators would have been paralysed by how to scale that they didn’t even begin!
  • #6 That’s me on every single startup idea I’ve ever had. Which is why I love seervelress so much. Becas it handles th eissues of scaling leading me to building the next twitter! I knew how to make an api with express but I didn’t know how to build an api with servers and that’s what we’re going to talk about today. And that’s the topic of today’s talk? https://www.istockphoto.com/photo/three-young-nerds-with-thinking-caps-gm678860582-125092811
  • #8 Serverless computing is the abstraction of servers, infrastructure, and operating systems. When you build serverless apps you don’t need to provision and manage any servers, so you can take your mind off infrastructure concerns. Serverless computing is driven by the reaction to events and triggers happening in near-real-time—in the cloud. As a fully managed service, server management and capacity planning are invisible to the developer and billing is based just on resources consumed or the actual time your code is running.
  • #9 https://martinfowler.com/articles/serverless.html
  • #10 Serverless computing is the abstraction of servers, infrastructure, and operating systems. When you build serverless apps you don’t need to provision and manage any servers, so you can take your mind off infrastructure concerns. Serverless computing is driven by the reaction to events and triggers happening in near-real-time—in the cloud. As a fully managed service, server management and capacity planning are invisible to the developer and billing is based just on resources consumed or the actual time your code is running.
  • #15 Serverless computing is the abstraction of servers, infrastructure, and operating systems. When you build serverless apps you don’t need to provision and manage any servers, so you can take your mind off infrastructure concerns. Serverless computing is driven by the reaction to events and triggers happening in near-real-time—in the cloud. As a fully managed service, server management and capacity planning are invisible to the developer and billing is based just on resources consumed or the actual time your code is running.
  • #16 And the way this talk is structured is a series of I don’t knows, things that I know how to do when using express but had to learn with serverless. And some of them might be exactly how you expected it to, but we still need to go through the effort of understanding them.
  • #19 So here we have an angular app that’s connecting to an express backend. And what we can do is Create new puppies, list exsiting ones, edit puppis and delete them. So basically the typical CRUD operations. And the goal is to take this app and instead of connecting to an express back end we should insteab be able to call serverless endpoints.
  • #20 https://raw.githubusercontent.com/ashleymcnamara/Developer-Advocate-Bit/master/BABY_BIT.png Explain why , set of stories list all tasks Creating a project Add section on serverless - spend a minute or two on this; what is serverless
  • #21 https://raw.githubusercontent.com/ashleymcnamara/Developer-Advocate-Bit/master/BABY_BIT.png I want you to take a very good loooooong look at this logo. This has been one of the most controversial logos in the entire history of text editor logos. It’s also the logo of the editor that will help you the most with building servrless apps. Empty IDE IDE with the extension installed
  • #22 https://raw.githubusercontent.com/ashleymcnamara/Developer-Advocate-Bit/master/BABY_BIT.png I want you to take a very good loooooong look at this logo. This has been one of the most controversial logos in the entire history of text editor logos. It’s also the logo of the editor that will help you the most with building servrless apps. Empty IDE IDE with the extension installed
  • #23 https://raw.githubusercontent.com/ashleymcnamara/Developer-Advocate-Bit/master/BABY_BIT.png I want you to take a very good loooooong look at this logo. This has been one of the most controversial logos in the entire history of text editor logos. It’s also the logo of the editor that will help you the most with building servrless apps.
  • #24 Once we have the extension installed we can go ahead and create a new function on our computer. First thing that will be created is a function app that allows us to group together functions with similar functionality and also configure settings that will apply to all functions within the same functionapp. To create a new function app we need to Click this folder icon on our extension, choose the language that we want to use. Once that’s done a vscode folder will be generated for us which will include the debuggging cofnig for us. Another important file that’s being generated is the local.settings.json file. This is where we’ll store our secrets, our environment variables. Stop looping
  • #26 This will generate a few files for us so let’s see what each of them does. The function.json file defines the function bindings and other configuration settings. The runtime uses this file to determine the events to monitor and how to pass data into and return data from function execution. The index.js file is where our functions’ code lives. Sample.dat contains test data.
  • #27 All files are stored inside a folder named just like our function
  • #31 https://raw.githubusercontent.com/ashleymcnamara/Developer-Advocate-Bit/master/BIT_VSCODE.png
  • #33 https://raw.githubusercontent.com/ashleymcnamara/Developer-Advocate-Bit/master/node.png
  • #35 https://github.com/ashleymcnamara/Developer-Advocate-Bit/blob/master/AZURE.png
  • #44 Cross-origin resource sharing (CORS) is a mechanism that allows restricted resources (e.g. fonts) on a web page to be requested from another domain outside the domain from which the first resource was served.
  • #45 In your local.settings.json What is cors
  • #46 https://github.com/ashleymcnamara/Developer-Advocate-Bit/blob/master/bit_octocat.png There’s actually more than one option here. The first and the easiest is deploying using the same azure functions extension. This will zip up your code and you node modules and push them to the cloud. Pretty straighforward. And easy to use.
  • #47 There’s actually more than one option here. The first and the easiest is deploying using the same azure functions extension. This will zip up your code and you node modules and push them to the cloud. Pretty straighforward. And easy to use.
  • #50  https://www.youtube.com/watch?v=FGJnBWWxTos
  • #51  https://www.youtube.com/watch?v=FGJnBWWxTos
  • #52 Javascript is easy to get started with and friendly to beginners.