Categories
Node.js Node.js Quick Tips Quick Tips

Command-line argument parsing with Node.js core

3 min read

Categories
Node.js

Deploying a Node app and Postgres database to Fly.io

6 min read Jump links Prepare the application for deployment Configure the Node.js server to listen on all network interfaces Set a Node.js version in package.json Set up the Fly CLI We’ll use the Fly CLI for creating, configuring and deploying our application to Fly. We can follow the Installing flyctl documentation to install the Fly CLI. Once […]

Categories
Fastify Node.js

Use Fastify hooks to set headers on every response

4 min read Jump links Fastify hooks and encapsulation contexts Example of an onSend hook Set headers for a collection of routes Set headers for all server routes Approach 1: Register an onSend hook in the server’s root context Approach 2: Register an onSend hook inside a plugin and wrap it with fastify-plugin Useful links

Categories
Node.js What's new in Node.js core?

What’s new in Node.js core? March 2022 edition

3 min read 🌟 New features 🎞️ Video walkthrough 💎 Other notable features 📅 Node.js releases

Categories
Node.js Quick Tips Quick Tips

The Fetch API in Node.js

< 1 min read Example Support in Node.js When can you use it in production? Related links

Categories
Node.js Quick Tips Quick Tips

Avoid boilerplate code when handling abort signals

< 1 min read Example Support in Node.js When can you use it in production? Related links

Categories
Node.js Quick Tips Quick Tips

Provide context with abortSignal.reason

< 1 min read Example: Trigger an abort signal with a reason (can be any value) Support in Node.js When can you use it in production? Related links

Categories
Node.js Quick Tips Quick Tips

Import JSON in ES modules

2 min read Example A: Static import with JSON import assertion Example B: Dynamic import with JSON import assertion Support in Node.js When can you use it in production? Related links

Categories
Node.js Quick Tips Quick Tips

Automatically cancel async operations with AbortSignal.timeout()

2 min read Example A Example B Support in Node.js When can you use it in production? Related links

Categories
Node.js Quick Tips Quick Tips

Deep clone values with structuredClone()

< 1 min read Example of an object being deep cloned Support in Node.js When can you use it in production? Related links

Categories
Building My Indie Business

2021 year in review

8 min read Jump links A year of firsts Client work Technical writing Products Ebook: Express API Validation Essentials Workshop: Node Validation Essentials Traditional book publishing Content Twitter Blog posts Videos Mailing list Plans for 2022

Categories
Node.js

Get started with validation in Node.js

4 min read A powerful validation duo Creating a schema and validating data Schema generation Try it yourself Wrapping up Further reading

Categories
Node.js Videos

Talk: Improving your applications with AbortController

< 1 min read

Categories
Node.js

How to cancel an HTTP request in Node.js

5 min read The Abort API Cancelling an HTTP request with an AbortSignal Support for cancelling HTTP requests Wrapping up

Categories
Node.js

Guidelines for choosing a Node.js framework

7 min read Jump links What’s your use case? Framework styles Support for promises and async / await Documentation Practical examples Community and ecosystem Project health Conclusion

Categories
Fastify Videos

Workshop recording: Get Started with Fastify

< 1 min read

Categories
Node.js Quick Tips Quick Tips

Generate v4 UUIDs without needing the uuid library

< 1 min read

Categories
Node.js Quick Tips Quick Tips

Cancel async operations with AbortController

< 1 min read

Categories
Node.js Quick Tips Quick Tips

Make your imports clearer with the node: protocol

< 1 min read Example Support in Node.js Related links

Categories
Node.js Quick Tips Quick Tips

Take advantage of promise-based APIs in Node.js

2 min read timers/promises module stream/promises module readline/promises module fs/promises module dns/promises module

Categories
Node.js What's new in Node.js core?

What’s new in Node.js core? September 2021

< 1 min read

Categories
Fastify Learning Fastify Node.js Videos

Learning Fastify: How to migrate your app from Express to Fastify

< 1 min read Links

Categories
Express Node.js

How does middleware work in Express?

5 min read Jump links The middleware pattern Middleware syntax The two types of middleware Plain middleware Error handling middleware Using middleware At the route level At the router level At the application level Wrapping up

Categories
Fastify Node.js

How to migrate your app from Express to Fastify

12 min read Jump links What are the benefits of migrating from Express to Fastify? How to Migrate an API with Confidence Transitioning from Express to Fastify with fastify-express Our Example Express Application Required dependencies The router module The app module The server module Running our application Migrating Our Application from Express to Fastify Required dependencies Refactoring our […]

Categories
Node.js

Notes from CityJS Conference 2021

17 min read Jump links Talk: Deno and TypeScript: The Good, The Bad and The Ugly Talk: Supercharge your JavaScript with WebAssembly Talk: New and experimental features in Node.js core Talk: 10 secrets to improve Node.js Security Talk: The Third Age of JavaScript Talk: Next-gen Frontend tooling Talk: Authentication, authorisation and security for modern client-side applications Talk: A […]

Categories
Node.js Quick Tips Quick Tips

Tips for migrating from Express to Fastify

2 min read Server creation and configuration is quite similar Fastify plugins are configured a little differently to Express middleware Express routes won’t show up when you call fastify.printRoutes() Fastify automatically serializes objects and arrays to JSON when you send them

Categories
Fastify Node.js Videos

Talk: Make the most of modern JavaScript with Fastify (2021-02-25)

< 1 min read

Categories
Command Line Quick Tips Quick Tips

Background a process in the terminal

< 1 min read

Categories
Node.js

Are you using promises and async / await safely in Node.js?

5 min read Jump links Support for async code in Node.js What does framework “native support” for async code look like? What happens when a framework doesn’t natively support async code? Which Node.js frameworks natively support async code? How to write async code safely in Node.js Build new projects with a framework which natively supports it Migrate existing […]

Categories
Node.js Quick Tips Quick Tips

How to speed up npm install in your Node.js builds

< 1 min read

Categories
Fastify Learning Fastify Node.js Videos

Learning Fastify: Create a proxy server for API authentication

< 1 min read Links

Categories
API Essentials Fastify Node.js

How to securely call an authenticated API from your front end

5 min read Jump links Request flow with a proxy server Create a server with Fastify Add and configure the fastify-http-proxy plugin Add an API key to proxied requests HTTP request header URL query string Conclusion

Categories
ECMAScript modules Node.js

What you need to know about ES modules in Node.js

7 min read Jump links Several names for the same thing Which versions of Node.js have full support for ES modules? Why are ECMAScript modules marked as ‘Experimental’ in the Node.js documentation? ES and CommonJS modules play nice together (mostly) Use ES modules when you start a new Node.js project It’s probably not worth migrating your existing Node.js […]

Categories
JavaScript Quick Tips Quick Tips

How to use the nullish coalescing operator

< 1 min read

Categories
Fastify Node.js Videos

Trying out HTTP Toolkit with fastify-http-proxy

< 1 min read Links

Categories
Express Node.js

Send awesome structured error responses with Express

9 min read Jump links Introducing the ‘Problem Details for HTTP APIs’ specification Problem types and Problem details objects Example problem details response More details, clearer problems Breakdown of a problem details object How to send problem details responses with Express Define problem types and map them to JavaScript error classes Look up the problem details for an […]

Categories
Node.js Quick Tips Quick Tips

Don’t install body-parser – it’s already bundled with Express

< 1 min read

Categories
Node.js Quick Tips Quick Tips

Only use dotenv in development

< 1 min read

Categories
Express Node.js

How to create an error handler for your Express API

7 min read Jump links Getting errors to error handler middleware Creating an error handler Error handler concerns Error handler middleware function Error handler helper functions Applying the error handler middleware Example error response Next steps Getting errors to error handler middleware Creating an error handler Error handler concerns Error handler middleware function Error handler helper functions Applying […]

Categories
Node.js Quick Tips Quick Tips

Express uses finalhandler for the default error handler

< 1 min read

Categories
Building My Indie Business

Week Notes #6

2 min read

Categories
Node.js Quick Tips Quick Tips

How to list npm run scripts for a project

< 1 min read

Categories
Building My Indie Business

Week Notes #5

1 min read What went well this past week? I received an email from one of my subscribers thanking me for the newsletter which I send out weekly-ish. They said a bunch of very kind things that made me grin from ear to ear and it absolutely made my Friday. Metrics such as open rates, click throughs etc. […]

Categories
Node.js Quick Tips Quick Tips

Name your functions for better stack traces

< 1 min read

Categories
Express Node.js

How to handle request validation in your Express API

9 min read Jump links Getting to grips with JSON Schema Why should I use JSON Schema and not validation library X? How to integrate validation with JSON schemas into your application Pulling it all together Wrapping things up Handy JSON Schema links

Categories
Node.js Quick Tips Quick Tips

Display the internal Express logs to help you debug your application

< 1 min read

Categories
API Quick Tips Quick Tips

Try a standard format for API error responses

< 1 min read

Categories
Building My Indie Business

Week Notes #4

< 1 min read

Categories
Git Quick Tips Quick Tips

How to restore changes which you’ve reverted from your main git branch

2 min read

Categories
Node.js Quick Tips Quick Tips

What are the Express req and res objects?

< 1 min read

Categories
Node.js Quick Tips Quick Tips

How to generate a stack trace in Node.js

< 1 min read

Categories
Node.js

Notes from NodeConf Remote 2020

9 min read Talk: Aaaaaaaaaaaaaah, They’re Here! ES Modules in Node.JS Talk: Can we double HTTP client throughput? Talk: AsyncLocalStorage: usage and best practices Talk: Examining Observability in Node.js Talk: Node.js startup performance

Categories
Command Line Quick Tips Quick Tips

How to output the contents of a file in reverse

< 1 min read

Categories
Building My Indie Business

Week Notes #3

< 1 min read

Categories
Building My Indie Business

Week Notes #2

2 min read

Categories
JavaScript Quick Tips Quick Tips

Ditch !! and try Boolean() instead

< 1 min read

Categories
Express Node.js

How to send consistent error responses from your Express API

6 min read When you’re building an API with Express it can be difficult to know how to send consistent error responses. The framework doesn’t seem to provide any special features for this, so you’re left to figure it out on your own. At some point you’ll probably find yourself wondering if you’re doing it “the right way”.

Categories
Git Quick Tips Quick Tips

Save your git stashes with helpful descriptions

< 1 min read

Categories
Building My Indie Business

Week Notes #1

3 min read

Categories
Command Line Quick Tips Quick Tips

cURL download file command

< 1 min read

Categories
Express Node.js

How to fix those confusing CORS errors when calling your Express API

6 min read

Categories
Command Line Quick Tips Quick Tips

Use the GitHub CLI to help reduce context switching

< 1 min read

Categories
JavaScript Quick Tips Quick Tips

Using object shorthand when debugging

< 1 min read

Categories
Node.js Quick Tips Quick Tips

Format JavaScript objects and arrays in debug output

< 1 min read

Categories
Git Quick Tips Quick Tips

How to review your changes with git piece by piece before committing

2 min read

Categories
ECMAScript modules Node.js

Node.js now supports named imports from CommonJS modules, but what does that mean?

5 min read Node.js v14.13.0 introduces support for named imports from CommonJS modules. Sounds great, right? But I realised I had no idea what this actually meant. Join me on my journey of discovery!

Categories
Node.js Quick Tips Quick Tips

Try out command line tools with npx

< 1 min read

Categories
API Essentials

How to build filtering into your REST API

4 min read

Categories
API Essentials

How to use fetch to POST form data as JSON to your API

4 min read

Categories
Express Node.js

5 best practices for building a modern API with Express

4 min read Jump links Enable the full use of promises and async / await 2. Validate request data with JSON Schema 3. Use an existing format for error responses 4. Send CORS response headers so web pages can call your API 5. Separate your concerns

Categories
Node.js

What is a good directory structure for a monorepo with a Node.js back end and React front end?

3 min read

Categories
Express Node.js

How can I handle common checks across different endpoints in an Express application?

3 min read