:: krowemoh

Wednesday | 15 OCT 2025
Posts Links Other About Now

previous
next

Making A Node Utility into a Binary

2025-10-04
node, js

I don't always have node set up for every user and there are node packages I would like people to have access to.

The solution was to package a node utility into a binary and then have people use that binary. This way I don't need to set up each user with something like nvm.

Unfortunately the pkg utility is deprecated but I found it much easier to use than anything else and I'm using an old version of node anyway, so I figure I'll just use an old version of pkg.

I am going to use node 16.19 and build a binary out of the livereload package.

The first step is to install pkg:

nvm use 16.19
npm install -g pkg

The next step is start a new node project and initialize it.

mkdir livereload-bin
cd livereload-bin
npm init

Once the package is initialized, we can then add livereload:

npm install livereload

Now the package is installed and ready to be converted:

pkg node_modules/livereload/bin/livereload.js --output livereload

This should run pretty quickly and result in a usable livereload binary. You can then move this to /usr/local/bin and if that's part of the PATH, then it should now be avaiable to users that don't have node.

I also made changes to the livereload function so that it sets an extra variable and lets me watch file changes in places that it filters out. The conversion to binary worked flawlessly.