Sign in

Luciano Mammino 📙 Node.js Design Patterns

@loige.co
2.1K followers 881 following 1K posts

AWS Serverless Hero & MVP. Senior Architect fourTheorem, author of 📕 nodejsdp.link & ✉️ fstack.link Node.js, JavaScript, Rust 🦀 & Cloud ☁️

PostsRepliesMedia
Reposted by Luciano Mammino 📙 Node.js Design Patterns
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
I've used #Docker for 10+ years and I thought I knew how image layers work. Then I asked one innocent question: if layers are just tar archives stacked on top of each other, how can a layer DELETE a file from a previous one? 🧵 loige.co/hidden-desig...
loige.co
The hidden design compromises of Docker layers
How Docker and OCI image layers represent filesystem changes, why deleting a file needs special whiteout entries, and what happens if you create a file called .wh.foo.
121
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
@fntlnz.wtf
000
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
... Also my docker captain friends might like this (...or tell me I am an idiot for not knowing earlier 🫡) @gianarb.it @francescociulla.bsky.social
101
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
If you found this useful (or just learned something weird about Docker today 😄), please share the article with a friend or colleague who works with containers. It really helps! And if you already knew about whiteouts, congrats: you were several "layers" ahead of me 🐇
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
All the experiments are reproducible, with scripts, raw logs and the full version matrix: github.com/lmammino/bro...
github.com
GitHub - lmammino/broken-dockerfile: It works on my machine. Then you push it. An experiment on .wh.* file names and OCI whiteouts.
It works on my machine. Then you push it. An experiment on .wh.* file names and OCI whiteouts. - lmammino/broken-dockerfile
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
In the article: • how layers work as tar-based changesets • why deletes never shrink your image • whiteouts & opaque dirs • 4 experiments that break a Dockerfile • the design compromises behind it all (spoiler: AUFS) Hack or elegant pragmatism? Tell me what you think! 👇
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
Which raises the obvious question: what if my file is literally called .wh.foo? Linux is fine with it. OCI layers can't represent it. So of course I tried it with BuildKit... 🧪 It builds. It runs. It works on my machine. Then you push it, and foo disappears everywhere else 🙃
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
That's a "whiteout". As far as tar is concerned, it's just a weirdly named regular file. It's the OCI unpacker that sees the name and says: "ah, you actually want foo gone". There's even a stranger one: .wh..wh..opq, which hides everything a directory inherited from earlier layers.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
Tar can say "here's a file". It can say "here's a new version of that file". But it has no way to say "remove this file from the archive below me". So the OCI image spec has a trick: to delete foo, a later layer ships an entry called .wh.foo 🫥
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 14h
I've used #Docker for 10+ years and I thought I knew how image layers work. Then I asked one innocent question: if layers are just tar archives stacked on top of each other, how can a layer DELETE a file from a previous one? 🧵 loige.co/hidden-desig...
loige.co
The hidden design compromises of Docker layers
How Docker and OCI image layers represent filesystem changes, why deleting a file needs special whiteout entries, and what happens if you create a file called .wh.foo.
121
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
Thx 😊 the first part of the thread was a bit of a hook, but I believe the rest of it + the article deliver good value
020
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
I have definitely done this mistake myself more than once, so i think it's a great example of one of those little details that can go wrong with env vars. It's part of my more comprehensive article, which hopefully covers many more useful tips, tricks and gotchas... I hope you'll like it ;)
110
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
The pattern that ties it all together: one config module, validated at startup, fail fast. The rest of the code never touches process.env directly. Full guide (validation with Zod, security, NODE_DEBUG and friends): nodejsdesignpatterns.com/blog/nodejs-...
nodejsdesignpatterns.com
Environment Variables in Node.js
Learn how to use environment variables in Node.js with process.env, the native --env-file flag, validation, and security best practices.
020
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
NODE_ENV=production does not make your app faster by itself. It's a convention, not a Node.js feature. It just tells your dependencies (Express, React, bundlers) to behave like production. If they don't check it, nothing changes.
110
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
Speaking of child processes: spawn('node', ['worker.js']) hands the child a copy of your ENTIRE environment, DATABASE_URL and all. Pass an explicit allowlist instead: spawn('node', ['worker.js'], { env: { PATH: process.env.PATH, WORKER_ID: '1' } })
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
Now the uncomfortable part: env vars are a mediocre home for secrets. - child processes inherit them by default - they show up in docker inspect - readable from /proc/PID/environ - crash reporters love to capture the whole environment Prefer a secrets manager in production.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
Need to load .env programmatically? Also built in (20.12+): process.loadEnvFile('.env') And util.parseEnv() parses .env-formatted strings from any source, like a config service response.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
It layers nicely too: node --env-file=.env --env-file=.env.local app.js Later files win. And since 22.9 there's --env-file-if-exists for optional files. One gotcha: OS variables always beat the .env file. The file provides defaults, it never overrides.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
You probably don't need dotenv anymore. Since Node.js 20.6: node --env-file=.env app.js Zero dependencies, no code changes. The .env format is compatible with what you already have.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
The "false" trap: FEATURE_ENABLED=false node app.js if (process.env.FEATURE_ENABLED) { // this runs 😱 } "false" is a non-empty string, so it's truthy. Always compare explicitly: process.env.FEATURE_ENABLED === 'true'
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
Everything in process.env is a string. process.env.PORT = 3000 typeof process.env.PORT // 'string' Even null and undefined get stringified to 'null' and 'undefined'. Parse numbers and booleans explicitly at startup.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
Environment variables in Node.js look trivial until they bite you: everything is a string, "false" is truthy, and every child process you spawn inherits your secrets. I just published a complete guide. Here's the short version 🧵
Infographic titled “Node.js Environment Variables: Simple until they bite you.” On a dark, neon green and cyan tech-style background, five panels explain key pitfalls and best practices: (1) everything in process.env is a string, for example PORT becomes "3000"; (2) the “false” trap, where "false" is still truthy in JavaScript; (3) built-in .env loading in modern Node.js with --env-file; (4) layered .env files, where later files win but OS environment variables still override; and (5) security risks, showing child processes inheriting secrets by default. A green banner at the bottom highlights the best practice: use one validated config module, fail fast, and keep secrets out of environment variables in production. The full guide URL appears at the bottom: nodejsdesignpatterns.com/blog/nodejs-environment-variables.
110
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
Answer: 'feature on'. 🧐 Every env var is a string, and 'false' is a non-empty string. This one bites everyone at least once.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 06/07/2026
⚡️ 🐢🚀 Node.js QUIZ 🐢🚀 ⚡️ ``` FEATURE_ENABLED=false node app.js ``` Then, in app.js: ``` if (process.env.FEATURE_ENABLED) { console.log('feature on') } ``` What gets printed? 🤨
210
Reposted by Luciano Mammino 📙 Node.js Design Patterns
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 05/06/2026
🎉 Big news: Node.js is changing its release schedule for the first time in 10 years. From October 2026, less to remember and easier to know what's Current or LTS. Here's everything you need to know 🧵👇
141
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 05/06/2026
💚 Best part: it's the project simplifying itself to match how people actually use it, and easing the load on the volunteers who keep Node.js alive 🙏 Full breakdown here 👇 nodejsdesignpatterns.com/blog/nodejs-... #nodejs #javascript
nodejsdesignpatterns.com
Node.js is changing its release schedule and version numbers
Node.js is moving to one major release a year, year-based version numbers, every release becoming LTS, and a new Alpha channel. Here is what changes.
040
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 05/06/2026
♻️ Every release becomes LTS. No more "wait, is it odd or even?" 🙃 🧪 A new Alpha channel (27.0.0-alpha.1) gives library authors a 6-month window to test breaking changes early.
110
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 05/06/2026
🗓️ One major release a year (Current in April, LTS in October) 🔢 Version number lines up with the year: Node.js 27 in 2027, 28 in 2028, 29 in 2029. Ubuntu users will feel right at home 😉
110
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 05/06/2026
🎉 Big news: Node.js is changing its release schedule for the first time in 10 years. From October 2026, less to remember and easier to know what's Current or LTS. Here's everything you need to know 🧵👇
141
Reposted by Luciano Mammino 📙 Node.js Design Patterns
Mr SheerLuck @mrsheerluck.bsky.social · 20/05/2026
Published another article for my Rust series Learn Rust Iterators by Building a Git Object Store Reader #rust #rustlang #programming blog.sheerluck.dev/posts/learn-...
blog.sheerluck.dev
Learn Rust HashMap and Iterators by Building a Git Object Store Reader | Mrsheerluck Blog
In this post, we are going to build a git object store reader in Rust and learn hashmaps and iterators in Rust
042
Reposted by Luciano Mammino 📙 Node.js Design Patterns
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
The article shows the new API side-by-side with the old one for every feature, plus a companion GitHub repo with every snippet ready to clone and run. I hope you'll like it 🙂 nodejsdesignpatterns.com/blog/whats-n...
nodejsdesignpatterns.com
What's new in Node.js 26
Node.js 26 ships the Temporal API by default, Map upsert helpers, Iterator.concat, V8 14.6 and Undici 8. A code-heavy tour with practical examples.
011
Reposted by Luciano Mammino 📙 Node.js Design Patterns
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
Node.js 26 shipped this week 🎉 My birthday is close, so I'm officially calling it an early birthday present from the Node.js team. 😂 This release doesn't look flashy at first glance, but the additions are genuinely useful in everyday code. I wrote a code-heavy tour, here's what stood out 🧵
192
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
The article shows the new API side-by-side with the old one for every feature, plus a companion GitHub repo with every snippet ready to clone and run. I hope you'll like it 🙂 nodejsdesignpatterns.com/blog/whats-n...
nodejsdesignpatterns.com
What's new in Node.js 26
Node.js 26 ships the Temporal API by default, Map upsert helpers, Iterator.concat, V8 14.6 and Undici 8. A code-heavy tour with practical examples.
011
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
Plus the cleanup: private _stream_* modules, writeHeader(), and --experimental-transform-types are all gone. module.register() is runtime-deprecated. If you maintain libraries, this is a good time to grep for those.
120
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
V8 14.6 + Undici 8 under the hood. Beyond the new methods covered above, you also get JIT and GC improvements across the board. Some apps will see a free performance bump just from upgrading.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
Iterator.concat() composes lazy iterables into a single iterable without ever materializing intermediate arrays. One catch though: it's sync-only. For async iterables you'll need a small concatAsync helper, and the article includes a one-liner you can paste in.
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
Map.getOrInsert(key, value) and getOrInsertComputed(key, factory) are now built in. The classic if(!map.has(k)) { map.set(k, ...) } return map.get(k) pattern collapses to one atomic call. The same pair landed on WeakMap, perfect for per-instance metadata.
130
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
Temporal is finally stable and enabled by default. You can drop Moment.js / Luxon / date-fns. The global Temporal handles dates, time zones, and DST math correctly out of the box. If you've ever shipped a "remind me in one day" feature that drifted by an hour twice a year, this is for you.
130
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 10/05/2026
Node.js 26 shipped this week 🎉 My birthday is close, so I'm officially calling it an early birthday present from the Node.js team. 😂 This release doesn't look flashy at first glance, but the additions are genuinely useful in everyday code. I wrote a code-heavy tour, here's what stood out 🧵
192
Reposted by Luciano Mammino 📙 Node.js Design Patterns
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 03/05/2026
New post: Writing middlewares for #Rust #Lambda functions 🦀 The #AWS Lambda Rust runtime already ships a middleware engine: tower. Almost nobody is using it. Deep dive + a complete DynamoDB rate limiter you can steal: loige.co/writing-midd...
loige.co
Writing middlewares for Rust Lambda functions
How to write reusable middleware for Rust Lambda functions using tower, the generic middleware engine that already underpins the AWS Lambda Rust runtime. Includes a complete DynamoDB-backed IP rate li...
131
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 04/05/2026
@rustaceans.bsky.social hey John & Elley, big fan of your newsletter here! I hope you'll consider my last article loige.co/writing-midd... for your next issue :) It's a pretty long one but hopefully it covers Tower in a way that can be useful even to folks who don't target AWS Lambdas (yet).
loige.co
Writing middlewares for Rust Lambda functions
How to write reusable middleware for Rust Lambda functions using tower, the generic middleware engine that already underpins the AWS Lambda Rust runtime. Includes a complete DynamoDB-backed IP rate li...
000
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 03/05/2026
PS: the post is sprinkled with rabbit holes 🐇 — curious (and hopefully interesting) deep dives into things like async fn in traits, hand-rolled futures, fixed window vs token bucket, why `CorsLayer` works on Lambda, and more. Make sure to click into some of them. Just try not to get lost in them 😉
020
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 03/05/2026
All the code lives at: github.com/lmammino/rus... Clone it, `sam deploy`, and you are 5 minutes away from a working tower-based rate limiter on AWS. Let me know what you build with it 👀
github.com
GitHub - lmammino/rust-lambda-middleware-example: A sample rate limit middleware for your Rust lambdas
A sample rate limit middleware for your Rust lambdas - lmammino/rust-lambda-middleware-example
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 03/05/2026
This is the same pattern that made Middy (middy.js.org) so useful in Node.js Lambda. I started Middy back in 2017, but huge props to the community and especially Will Farrell for keeping it growing all these years 🙏
middy.js.org
Middy.js
The stylish Node.js middleware engine for AWS Lambda
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 03/05/2026
What's inside: → tower's Service + Layer traits, from no-op to real → Why `Service::call` can't be async (and the `Box::pin(async move)` fix) → Short-circuits, errors, and the up/down trip → A full DynamoDB-backed IP rate limiter → SAM deploy in 5 minutes
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 03/05/2026
Why bother? Once you start thinking in layers, you can stack auth, logging, validation, response shaping, CORS, and rate limits as composable Services. The handler stays focused on the one thing it actually cares about: business logic 🎯
100
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 03/05/2026
New post: Writing middlewares for #Rust #Lambda functions 🦀 The #AWS Lambda Rust runtime already ships a middleware engine: tower. Almost nobody is using it. Deep dive + a complete DynamoDB rate limiter you can steal: loige.co/writing-midd...
loige.co
Writing middlewares for Rust Lambda functions
How to write reusable middleware for Rust Lambda functions using tower, the generic middleware engine that already underpins the AWS Lambda Rust runtime. Includes a complete DynamoDB-backed IP rate li...
131
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 19/04/2026
Sorry seeing this only now! I love serverless and distributed systems, but at the same time I can't agree more with your suggestion. Everything has its place in systems architecture, but starting with something simple that can grow is always a wise choice!
030
Luciano Mammino 📙 Node.js Design Patterns @loige.co · 19/04/2026
Sorry I’m only getting back to this now. Life got busy :) Anyway, I really appreciate your message. It means a lot to hear that FSB was able to provide value to so many people I deeply respect, like you, David 🙌
010
Reposted by Luciano Mammino 📙 Node.js Design Patterns
James Eastham @jameseastham.co.uk · 10/04/2026
In my latest online course, I cover the fundamental integration patterns you will see most often in #serverless applications.. And this isn't just point to point vs pub/sub. This course covers a range of different #patterns, and importantly, how you can actually use these patterns in #production.
studyfromexperts.com
Serverless Integration Patterns
Learn practical knowledge for implementing integration patterns with AWS serverless services. This course goes far beyond what is in the Enterprise Integration Patterns book
032