Inspect Node Scripts With npm run

I have a project with many Node scripts in package.json. One way to inspect them without ever opening that file (in a nice formatted) is npm run. It gives an output like this: $ npm run Scripts available in exercism@1.0.0 via `npm run`: download:js sh -c 'exercism download --track=javascript --exercise="$1"' -- format-check:js prettier --check javascript/ lint:js oxlint javascript/ test-all:js NODE_OPTIONS=--experimental-vm-modules npx jest javascript validate npm run format-check:js && npm run lint:js && npm run test-all:js Try npm run in a JavaScript project to see it in action.

October 20, 2026

Node Evaluate String

Today I typed node -e <string> to see what happened. Answer: it evaluated my string argument. Here’s an example; printing the milliseconds since epoch without leaving the shell: > node -e "console.log(Date.now())" 1792427691395 Scripts that being with the minus symbol (-) are ambiguous, so you must add the -p / --print flag. > node --eval="-42" --print -42 See man node for more.

October 19, 2026

Comma Operator Return in JavaScript

I love learning something new that’s core to the JavaScript language syntax! A code exercise I completed today did just that. Via this comma, items is returned. const removeItemAtBottom = (items) => (items.shift(), items); const cards = [1, 2, 3, 4, 5]; removeItemAtBottom(cards); // [ 2, 3, 4, 5 ] This helps us around the fact that shift() returns the removed item, 1, rather than the list of items that we modified. It works outside a function as well: ...

October 1, 2026

Writing Math.max in JavaScript

For a recent talk I examined some JavaScript implementations in Node, and ended up reading the source code for Math.max, which does this: Math.max(100, 1); // 100 Here’s the code: extern macro Float64Max(float64, float64): float64; transitioning javascript builtin MathMax( js-implicit context: NativeContext)(...arguments): Number { let result: float64 = MINUS_V8_INFINITY; const argCount = arguments.length; for (let i: intptr = 0; i < argCount; i++) { const doubleValue = TruncateTaggedToFloat64(arguments[i]); result = Float64Max(result, doubleValue); } return Convert<Number>(result); } To better understand this function, I decided to write my own implementation in JavaScript: ...

September 27, 2026

JavaScripting on main()

I had ChatGPT write a JavaScript for me, and was surprised to see this arrangement: function main() { // Do work... } try { main(); } catch (error) { console.error(error); process.exitCode = 1; } I would not have written this file this way; instead, I’d have put a try/catch in the file directly and probably forgotten the exit code. This lets my script return nonzero on any error and be chained with other scripts. And it encapsulates the work in main(), a C-like flourish I admire.

September 23, 2026

toString can be set in JavaScript

A while ago, I wrote that you can use .toString() to reflect about user-defined functions in the JavaScript runtime. There’s a catch— this value can be set, making it not a reliable way to reflect the function. Create a confusing function: const one = () => '2'; Set it’s .toString to another function: one.toString = () => '1'; one.toString(); // '1' Now call the function: one(); // 2 .toString() was a lie!

September 9, 2026

Read Node's Process Versions

Node has a key process.versions that can tell us a lot about itself. Here’s one its many keys, telling me the V8 version of my Node with the -p / --print flag: node --print process.versions.v8 14.6.202.34-node.28 See node --print process for more.

September 9, 2026

JavaScript Reflection Preserves Comments

In JavaScript reflection with .toString(), comments are preserved. const hello = () => { // returns "Hello" return 'Hello'; }; hello.toString(); // '() => {\r // returns "Hello"\r return "Hello";\r}' Note the comment in the returned string.

September 9, 2026

Building a Pitchfork-Style Loading Skeleton

Today, after waiting for an album review to load, I built something small: my own take on the Pitchfork aggregate review loading experience. Pitchfork uses a Skeleton-style UI while returning an album’s aggregate review, such as “8.0” for Mastodon’s Crack the Skye. Skeleton UIs show you something, like blurred text or a flashing bar, to build anticipation and fill out the page while in a loading state. They are a fantastic UX touch for the right kind of app and data. In the case of the Pitchfork app, the aggregate review is a pivotal piece of information about an album, and is presumably being calculated on demand, so this choice makes sense. ...

September 2, 2026

Link to Local Package With npm link

When developing a local Node module, we might want to point another project’s package.json at the local module. Here’s how you do that. First, change directory to your local module and run npm link: cd ~/code/my-module npm link This creates a global symlink pointing at your module: npm ls -g --depth=0 --link /opt/homebrew/lib └── my-module@1.0.0 -> ./../../../Users/jake/code/my-module Then, change directory into the place you want to install the module and link the package: ...

September 2, 2026