“How to create a nodejs command line utility using cjs and typescript” — Part 1

Praveen David Mathew
6 min readFeb 7, 2022



This article series gives you a basic Idea on how to create a opensource command line utility project using Nodejs, Github Actions, and Jest

This article specifically focusses on creating a simple commandline utility using typescripe and cjs in nodejs.

See the package i created : https://www.npmjs.com/package/postman-collection-url-updater

Finding the purpose:

The first step of creating something is to find a purpose , a need on why we need something, ask your self following question

  1. What is the purpose of creating this (What problem does it solves)
  2. How often does people face this issue and looks out for a solution
  3. How much time does such a solution save
  4. What are the alternatives and its drawback

So, in my case there was a need of migrating the project from the URL structure {{baseURL}}/{{version}}/path1/path2 to {{baseURL}}/{{version}}/basepath/path1/path2

I could have just passed the additional path to version variable but doesn’t looks correct as the variable intention was to store just version . So I thought to create a npm command line utility that can update update

The second feature was the ability to move all collections into a single collection. I thought this would be really use full when you rearrange projects

A third feature of moving all folders into separate collection will be released in future 😍

Creating a command line nodejs utility:

I used es5 for this as it was a simple utility, you can use Typescript for more easy code. I will cover that later in this article.

Getting started:

  1. Create a folder with same name as your npm project name: (See the naming rules at : https://docs.npmjs.com/cli/v6/configuring-npm/package-json#name)
  2. open cmd with folder as cwd and run npm init -y
  3. now create a file called index.js
  4. Now create a folder called source and add a file called printer.js



Praveen David Mathew

An open source advocator/WebdriverIO Projectcommiter/Postman Supernova/Postman-html-extra contributor/Stack overflow sqa moderator/Speaker