šŸŽ Checkout my Learn React by Making a Game course and get 1 month Free on Skillshare!

Introduction to Javascript Serverless – functions as a service

The serverless term is quite misleading. There is still a server involved. However, when using a serverless service, such as Cloudflare, you don't have to worry about managing that server.

A serverless function runs only when needed. You pay just for the memory, storage CPUs, and data bandwidth used.

With serverless a new machine is spawned up when needed and shut down after. The service provider will also handle all the required infrastructure scaling when your app has a traffic spike.

This comes as an alternative to a traditional server provider, where you rent a given virtual or real machine. That machine is always up and running and you pay a fixed price for it.

Javascript serverless functions are stateless. For example:

let user = 'JS Craft'

const updateUser = newUser => user = newUser

const getUser = () => user

The getUser() function will ALWAYS return 'JS Craft', no matter how many times the updateUser() function was called.

Given that the serverless machines are shut down after the function runs, any session data is lost, therefore the value of user is reset.

Even if the serverless functions are stateless, you can still use databases to persist data. All serverless providers will give you access to a persistence layer.

Next let's see how to make your first call to a Javascript serverless function with with Cloudflare and vanilla Javascript.

šŸ“– 50 Javascript, React and NextJs Projects

Learn by doing with this FREE ebook! Not sure what to build? Dive in with 50 projects with project briefs and wireframes! Choose from 8 project categories and get started right away.

šŸ“– 50 Javascript, React and NextJs Projects

Learn by doing with this FREE ebook! Not sure what to build? Dive in with 50 projects with project briefs and wireframes! Choose from 8 project categories and get started right away.


Leave a Reply

Your email address will not be published. Required fields are marked *