At Sniptt, most of our experience has been writing TypeScript and JavaScript for Node, so we made the decision to use the same technologies to build out the first few versions of the Snip CLI. Our initial testing has shown, however, that distributing security software exclusively over npm would not sit right with many of our users. While our long-term goal is to port the Snip CLI to Golang, we decided to take a pragmatic approach until then and package our JavaScript code as stand-alone executable binaries for both macOS and Linux.
In this tutorial, we’ll show you how to build a simple Node.js CLI with TypeScript, and then package and distribute it via Homebrew.
TLDR; To view a completed setup including workflow automation, take a look at how we’ve done this with our official CLI at https://github.com/sniptt-official/snip-cli 😎.
Let’s start by initialising a new Node.js project called hello
via npm init
. This will create a package.json
file where we’ll keep track of our dependencies and scripts.
$ mkdir hello
$ cd hello
$ npm init -y
Next, let’s install TypeScript and the required Node.js typings, and then register our project with the TypeScript compiler. This will create a tsconfig.json
with default compiler options.
$ npm i typescript @types/node -D
$ npx tsc --init
#node #typescript #nodejs #cli