Backend Development 17 min read

A Guide to Useful Node.js Command‑Line Tools and Packages

This article explains the Unix‑style philosophy behind command‑line programs, describes how Node.js enables powerful CLI development, and introduces essential tools such as n/nvm, nodemon, npx, nrm, commander, progress, chalk, inquirer, ora, puppeteer, as well as best practices for publishing scoped npm packages.

360 Tech Engineering
360 Tech Engineering
360 Tech Engineering
A Guide to Useful Node.js Command‑Line Tools and Packages

Rooted in the Unix philosophy of doing one thing well, cooperating through pipelines, and using plain‑text interfaces, Node.js extends these ideas to both server‑side and front‑end build environments, making it an ideal platform for creating command‑line utilities.

A command‑line program is typically a text‑based interface that receives arguments; the first line often contains a #!/usr/bin/env node shebang, which tells the operating system which interpreter to invoke, allowing scripts to run without explicitly specifying the interpreter.

To manage multiple Node.js versions, developers can use n or nvm . Example installation commands are npm install -g n or curl -L https://git.io/n-install | bash for n , and curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.34.0/install.sh | bash for nvm . These tools download the requested version and adjust the system PATH accordingly.

For automatic restarts during development, nodemon watches files and restarts the process, e.g., nodemon ./server.js localhost 8080 . It can also run non‑Node scripts, such as nodemon --exec "python -v" ./app.py . The companion tool npx runs a package without installing it permanently, for instance npx http-server to start a quick static server.

Registry switching is simplified with nrm or yrm , which let users select faster npm or Yarn mirrors via commands like nrm use taobao .

When building CLI applications, the commander library provides a declarative API for defining options and sub‑commands. A minimal example is:

const program = require('commander');
program.version('0.1.0')
       .option('-p, --peppers', 'Add peppers')
       .parse(process.argv);
console.log('you ordered a pizza with:', program.peppers);

To display download progress, the progress package can be used together with request and request-progress :

const ProgressBar = require('progress');
const request = require('request');
const progress = require('request-progress');
// ... create a ProgressBar instance and update it inside the 'progress' event

For colored terminal output, chalk offers simple styling:

const chalk = require('chalk');
console.log(chalk.blue('Hello') + ' World' + chalk.red('!'));

Interactive questionnaires are handled by inquirer , which supports prompts, lists, checkboxes, and validation, making it easy to build rich CLI wizards.

The ora spinner provides elegant status indicators:

const ora = require('ora');
const spinner = ora('Loading unicorns').start();
setTimeout(() => { spinner.color = 'yellow'; spinner.text = 'Loading rainbows'; }, 1000);

For headless browser automation, puppeteer allows scripts to control Chrome/Chromium, useful for end‑to‑end testing and web scraping.

Finally, publishing a Node.js package is done with npm publish . Scoped packages use the @scope/name format and are published publicly via npm publish --access public . Including a prepublish script in package.json can run Babel or other build steps to ensure compatibility.

clijavascriptBackend DevelopmentNode.jsnpmcommand line tools
360 Tech Engineering
Written by

360 Tech Engineering

Official tech channel of 360, building the most professional technology aggregation platform for the brand.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.