The Edge is just a spicy CDN

Issue #97.April 24, 2022.2 Minute read.
Bytes

This week, we’re experimenting with our runtime features, learning about The Edge™️, and (hopefully) avoiding accidental tax fraud.

Welcome to #97.


Mountain Dew as a shower head meme

Some experiments pay off

Node gets experimental

Node 18 was released last week, and it celebrated becoming a legal adult by doing what lots of us did on our 18th birthday: vomiting tobacco and Flamin’ Hot Cheetos out our nose experimenting with stuff.

All of the big new features in Node 18 come with that spooky (experimental) flag, so make sure you know your limits when you’re trying them out. (I always recommend the buddy system.)

🔬 Experiment #1: global fetch API — This provides a standard around fetching data via http requests that’s similar to the popular node-fetch library but is “as close to browser spec-compliant as possible.” The Node team has been working on this for literally 4 years, but it turns out that it’s still impossible to please everybody.

🔬 Experiment #2: Test runner module — This new, built-in test runner lets you create and run Node tests without a third-party library. This is great news for smaller libraries looking to minimize dependencies and developers who just want to use Jest less (so, everyone).

🔬 Experiment #3: Web Streams API — This implementation of 17 different APIs is a lot. But the idea is that it allows you to use JavaScript to programmatically access streams of data and process them in a bunch of different ways.

The bottom line: We’re just happy to see Node being so productive despite the abandonment issues they must have been dealing with ever since dad Ryan Dahl left.


jeopardy answer of what is pain

Building notifications from scratch. [sponsored]

Courier’s new API saved me from my PM

You know that one person on your team who loves building complex notification systems?

Of course you don’t.

That’s because notifications have become a special kind of hell with tons of different platforms to worry about — email, SMS, chat, web and mobile push, Slack and more.

That’s what makes Courier’s simple API so powerful. It’s a one-stop shop for all notification platforms — so you can use the same API call to send your users an email, an SMS, a Slack message, or a push notification.

And their new Courier Elemental update gives you a JSON-based syntax to easily customize the design and content for each platform you send messages to.

This makes designing the actual notifications a lot less tedious, and it lets you create more dynamic notifications like magic login links and location based alerts.

So tell your PM to go as crazy as they want with notifications, because Courier’s got your back.

Check it out and get 10,000 free sends a month.


Severance meme

My innie trying to figure out wtf “the edge” is

Netlify and Deno are teaming up at The Edge™️

Netlify and Deno just announced that they’re partnering to deliver Edge Functions — a new serverless compute offering. Given that developers reference the “the edge” more than my mother-in-law’s flat earth Facebook group, we should probably address what the big deal is.

“The Edge”, otherwise known as a spicy Content Delivery Network (CDN), has been around for a while. CDNs provide the infrastructure to cache static content and deliver it from the closest server to the end user. Cloudflare changed the game when they released Workers in 2017, making it possible to run JavaScript at the edge.

Since then, hosting providers have been aggressively pursuing their own “edge compute” offerings. Like Workers, Deno & Netlify’s new offering is built on top of the V8 JavaScript engine and has a similar API to service workers in the browser. Here are some of the highlights:

  1. Cheap — 24x less expensive than standard serverless functions (3 million/month for free).

  2. Fast — without the overhead of containers, edge functions can start faster and run closer to the user, reducing latency.

  3. Web APIs — Because they’re built on web standards, code can be moved from the client to the server without many of the previous tradeoffs.

  4. New paradigm — Edge rendering can be nearly as fast as serving static files, potentially changing the paradigm for how developers think about building applications.

The Bottom Line: It’s hard to be more stoked about “the Edge” than I was in high school (closet U2 fan - terrible decision), but with companies like Cloudflare, Deno, and the rest of the homies working on it, “the Edge” definitely seems like the next big thing.


Jobs

Synapse Studios is looking for Senior JavaScript Engineers in the US

Synapse is a software consultancy (Node/React) with a focus on engineering excellence and tightly knit, low-ego teams. We believe devs want to feel productive, challenged, and supported and build our culture around those concepts. Come join our growing crew as we solve interesting challenges in healthcare, fitness, IoT, retail and more, for a variety of clients, at scale.


🔬 Spot the Bug — Sponsored by PostHog

PostHog is an open-source product analytics suite you can self-host. Heatmaps, Recordings, Funnels and more — all in a platform where you can build your own TypeScript plugins!

function calcPrice(price, tax, discount) {
  tax = tax || 0.05;
  discount = discount || 0;

  return price - price * discount + price * tax;
}

Cool Bits

  1. JSDB is a new tool that lets you use JavaScript as your database. Because when everyone’s super a backend developer, no one will be 😈

  2. Eleventy didn’t want to feel left out of EdgeWeek™️, so they announced plans for Eleventy Edge — a new plugin to run Eleventy in an Edge Function so you can easily add dynamic content to your sites.

  3. React - The Road to Enterprise is a new, advanced React book that’ll teach you industry-level techniques, best practices and concepts like advanced component and state management patterns, performance optimisation, scalable and maintainable architecture, testing, and much more. [sponsored]

  4. Óscar Otero created this Deno cheat sheet for no other reason than to help you feel superior to your co-workers. You’re welcome.

  5. Marcin Wanago wrote this 10-part series on JavaScript testing that covers a range of beginner and advanced topics. Thankfully, we can just use Node’s built-in test runner for everything now, so we’ll never have to read it.

  6. David East from the Firebase team made this 30-minute crash course that shows how to use Firestore and Firebase Auth together.

  7. Reasonable Colors is an open-source color system for building nice color palettes. Now if only we could get someone to create some Reasonable Tax Reform, so that I could pay the US government what I owe without having stress dreams about being thrown in prison for committing accidental tax fraud.


🔬 Spot the Bug — Sponsored by PostHog

The || operator checks for falsy values and 0 is a falsy value, which would accidentally apply the default tax rate. To fix this, instead of checking for a falsy value, you can use the nullish coalescing (??) operator.

function calcPrice(price, tax, discount) {
  tax = tax ?? 0.05;
  discount = discount ?? 0;

  return price - price * discount + price * tax;
}

The nullish coalescing operator works because it returns its right-hand side operand when its left-hand side operand is null or undefined (NOT 0), and otherwise returns its left-hand side operand.