Richard Clayton
Node.js and Kafka in 2018
Yes, Node.js has support for all of the Kafka features you need.
If you want to use Node and Kafka together and are struggling to find straightforward answers to some basic questions, I hope this helps you out. We've been building out an event system at Peachjar using Node and Kafka and some of this knowledge is the fruit of our research.
What are the popular Kafka clients in Node?
- . . .
Use State Machines!
FSMs are not as complex as you think and they make your code better.
What is a State Machine?
Finite State Machines (FSM, or in the context of this post, simply "State Machines") are a methodology for modeling the behavior of an entity with an established lifecycle. The lifecycle is defined by an enumerated set of states known at the time of implementation (this is where the term . . .
Posted in: architecturenodejs
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 . . .
Posted in: nodejs
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');
. . .
Posted in: nodejs
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 . . .
Posted in: nodejs
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 . . .
Posted in: nodejs
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 . . .
Posted in: nodejs