2 minutes
Cloudflare Workers Fun
Background
This past year, my son took an introductory JavaScript programming class. Like most everyone new to programming, he became frustrated a few times and asked for my help. Though I am not super familiar with the JavaScript programming language, we were able to work through the problems and concepts together until he had a better understanding.
I was very excited when he was able to explain the concepts of the language and how to use it. He ended the semester with a solid understanding and a respectable grade. Woohoo! Parenting success! As a bonus, I ended up learning a bit of JavaScript.
A holiday project
While on our winter holiday break, I was reading about Cloudflare Workers and how they can be used to create a serverless application. The native language of the Cloudflare Workers platform is JavaScript. With my very minimal knowledge of JavaScript learned while helping my son, I was able to create two quick and dirty Cloudflare workers.
Geolocation Worker
The first is a simple Geolocation worker that will return the user’s location based upon the IP Address Geolocation data provided by Cloudflare. A pretty version of the Geolocation information can be viewed at https://jak.onl/posts/stats and the raw JSON data that is returned can be viewed at https://jak.onl/api/geo.
Base64 Encoder/Decoder API Worker
The second worker is a simple API that will take input and encode/decode it to/from Base64. The API is located at https://jak.onl/api/base64.
I have made the repository available for download at https://github.com/JAKONL/base64
Closing
In total, I spent a few hours reading through the Cloudflare documentation and writing the JavaScript that powers these workers. It was great just how simple it was to get everything set up. The real time feedback provided by the wrangler dev
command allowed me to catch my mistakes and understand what was going on behind the scenes. I’m excited about the posibilities provided by the platform and will be thinking about what I can do with it next.