Richard Clayton

Scheduling Execution in Node.js

Differences between setTimeout, setImmediate, and process.nextTick.

A commonly misunderstood concept in Node.js is the difference between setTimeout, setImmediate, and process.nextTick. While all three functions are used to schedule the execution of a function, it is important to understand when Node.js will execute them.

Consider the following example:

setImmediate(() => console.log('Set . . .

Read More

Posted in: nodejs

March 14, 2018

Application Support in Docker-based Microservice Environments

How to provide essential services with minimal application involvement.

Introduction

Operationalizing microservices is difficult and that difficulty has been exacerbated by how much the landscape has changed over the last 5 years. Personally, I've worked on a few microservice architectures and experienced the evolution of thoughts, patterns, and technologies that have brought us to where we are . . .

Read More

March 10, 2018

Reduce Test Boilerplate with Generic Test Functions

I wanted to quickly mention a trick I use to reduce the boilerplate code you'll often encounter when executing similar test cases. Instead of defining each test separately:

const { describe, it } = require('mocha');
const { expect } = require('chai');

const app = require('../../index.js');
 . . .

Read More

Posted in: nodejs

March 07, 2018

The case against the generic use of PATCH and PUT in REST APIs

There is a lot of confusion among developers on how to implement updates using a REST API. The tools we are given (PATCH and PUT) don't actually map cleanly to how we would implement an update in our business code. Let's start by considering what those HTTP verbs mean:

PATCH: perform a partial update to a resource, . . .

Read More

March 07, 2018

Enumerations in Node.js and Mongoose

Enumerations are essential to writing good software. Enumerations provide a clear understanding of the set of values that can be used for a property. This ensures we can constrain input to the set of values in the enumeration. Enumerations also signal to the reader the intended behavior of model instances (particularly if the enumerated field . . .

Read More

Posted in: nodejs

March 05, 2018

Custom Errors in Node.js

I'm surprised how little custom errors are used in Node.js and I don't understand why.

I was integrating an open source library last week into a project and I was trying to write unit tests covering all failure cases one could expect with the library. The library, however, didn't make use of explicit error cases. This . . .

Read More

Posted in: nodejs

March 04, 2018

Node.js Process Events

Make sure you are listening to them!

I was troubleshooting a bug recently when I noticed an unrelated issue with one of my microservices. We were experiencing a failure in a non-critical component responsible for notifying our internal staff of a minor issue in our business workflow.

This was an issue our development team, extremely thorough QA team, and Ops team missed . . .

Read More

Posted in: nodejs

March 02, 2018

Archive

This update link alerts you to new Silvrback admin blog posts. A green bubble beside the link indicates a new post. Click the link to the admin blog and the bubble disappears.

Got It!