This blog post explores how to write CommonJS modules so that their exports can be name-imported from ESM modules on Node.js.
This blog post gives an overview of how Node.js works:
The npm package manager lets us define small shell scripts for tasks and execute them via npm run
. In this blog post, we explore how that works and how we can write them in a way that works across platforms (Unixes and Windows).
The package.json
property "bin"
lets an npm package specify which shell scripts it provides (for more information, see “Creating ESM-based shell scripts for Unix and Windows with Node.js”). If we install such a package, Node.js ensures that we can access these shell scripts (so-called bin scripts) from a command line. In this blog post, we explore two ways of installing packages with bin scripts:
Locally installing a package with bin scripts means installing it as a dependency inside a package. The scripts are only accessible within that package.
Globally installing a package with bin scripts means installing it in a “global location” so that the scripts are accessible everywhere – for either the current user or all users of a system (depending on how npm is set up).
We explore what all of that means and how we can run bin scripts after installing them.
util.parseArgs()
in Node.jsIn this blog post, we explore how to use the Node.js function parseArgs()
from module node:util
to parse command line arguments.
In this blog post, we learn how to implement shell scripts via Node.js ESM modules. There are two common ways of doing so:
In this blog post, we use TypeScript to ensure that an object stays in sync with an Array that lists its properties.
In this blog post, we learn how to work with file system paths and file URLs on Node.js.
An ESM module can be used in two ways:
If we want a module to be used in both ways, we need a way to check if the current module is the main module because only then do we execute the script functionality. In this blog post, we learn how to perform that check.
In this blog post, we’ll explore how we can execute shell commands from Node.js, via module 'node:child_process'
.