Node REPL, No Preview

After version v12.17.0, Node’s REPL provides a preview effect. In this example, if we type 1 + 1, Node shows us the result in gray before before hitting enter: > 1 + 1 2 But what if I don’t want that? Here’s a script called repl that disables it as an option: #!/usr/bin/env node const repl = require('node:repl'); repl.start({preview: false}); When we start Node via this script, we disable the preview: $ ./repl > 1 + 1 Customizing REPL Output – Official Node documentation

June 2, 2026

NVM Install and Use Latest LTS

With my Node versions managed via NVM, I want to be on the latest LTS. You can ensure that happens with these commands: $ nvm install --lts $ nvm alias default lts/* default -> node (-> v24.16.0) These two commands combine to say: “Install the latest LTS, and make my default that version.” See nvm --help for more information.

May 29, 2026

JavaScript Wraparound Index

What I call “wraparound” are repeatable indices on an array. The common use case is a carousel. Here’s how it’s done: const items = ['first', 'middle', 'last']; const i = 0; // Our iterable index // "Next" -> const nextIndex = (i + 1) % items.length; // <- "Previous" const prevIndex = (i - 1 + items.length) % items.length;

May 7, 2026

JavaScript String Concatenation

Here’s a periodic reminder that JavaScript supports string concatenation with a plus sign: > 'foo' + 'bar' 'foobar' This simple solution works just as well as the alternatives: // .join (common solution, in my experience) > ['foo', 'bar'].join('') 'foobar' // .concat > 'foo'.concat('bar') 'foobar' // Interpolation > `foo${'bar'}` 'foobar' A plus sign is all you need.

May 6, 2026

JavaScript Spread a String Into An Array

Need an array of letters? Here’s a trick: > const alpha = [...'abcdefghijklmnopqrstuvwxyz'] This assigns the following: > alpha [ 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' ] This is called spread syntax. Our string is iterable, and ... spreads them out into our array. MDN Spread Syntax

May 5, 2026

JavaScript Array Join Comma Default Separator

When you join an array in JavaScript, the default separator is a comma: node> ['j', 'a', 'k', 'e'].join() 'j,a,k,e' In production code, you often want to pass an empty string instead. node> ['j', 'a', 'k', 'e'].join('') 'jake' This is something I relearn from time to time, because it works differently in Ruby. irb> ["j", "a", "k", "e"].join() => "jake" MDN Array Join Docs

May 5, 2026

JavaScript Bitwise AND

The JavaScript bitwise AND operator (&) can be used for some real-world tasks, like testing if a number is odd or even. Odd-even checking might normally be done with a modulo and the number 2. // Checking 1 > 1 % 2 === 0 ? "Even" : "Odd" 'Odd' // Checking 2 > 2 % 2 === 0 ? "Even" : "Odd" 'Even' The bitwise AND is an alternative. When used between two numbers, it returns a new number that has 1’s in each position where both numbers have a 1. ...

May 1, 2026

Initialize With npm init

Most JavaScript projects come with a package.json. But what if you want to make a new one? This blog’s software is a great example. It’s statically rendered with Hugo, but as a JavaScript dev, I want my JavaScript tooling, too, so I need a manifest. If you install a single dependency, you’ll get a package.json with that dependency. It works, but it’s just a scaffold. The better command is: $ npm init This starts a dialog where you can choose sensible defaults for package name, version, description, entry point, Git repository, author, and license. It scaffolds you a test command, too. ...

February 12, 2026

Writing the DOM with fs

How can I output the entire DOM to a file in a JavaScript test? Testing Library is amazing. But, one area I struggle with it: when writing high-level integration tests, when an assertion fails, the output can be noisy and incomplete. It makes debugging tough. The test runner says something like: “I couldn’t find ‘Submit’ in these two thousand lines of HTML, which are so big I’ve truncated for you.” ...

January 30, 2026

Rebuilds on Write With Nodemon

I’ve been hacking on a TypeScript file all day, but I need transpiled JavaScript for any testing. How did I reduce cycle time (and mitigate many chances to forget to build at all)? My solution was a neat package called nodemon. With it, I set up a rebuild on write: nodemon --watch src/index.ts --exec "npm run build" When I write the file, I get a new build in seconds. Very cool! 🕶️

December 30, 2025