Node.js & NPM

Creating CLI Executable global npm module

Uday Hiwarale
JsPoint
8 min readMar 24, 2018

--

JavaScript has quickly became the most popular language on the planet and it is growing like anything. After ES6 and ES7, JavaScript official joined club of Object Oriented Programming languages. With async/await, it has become very easy to write asynchronous programs. The bigger success of JavaScript came with launch of Node.js which pushed JavaScript on server stack. Hence JavaScript is now found everywhere, from mobile applications, desktop applications, IoT devices, Servers to every day web browsers.

But above all, what I like the most about JavaScript, Node.js and npm together is the ability to build CLI applications. Somewhere in your life you might have opened the terminal and executed some command like git clone xxx or rm -rf xxx, these are all CLI commands referring to some program like git and rm. We can also install a npm module globally which means we can refer to that module from anywhere in our system using terminal commands.

When you install a module globally, npm will place that module inside a fixed folder (let’s call it npm folder), for example in Windows it could be$user/AppData/Roaming/npm or any other folder depending on your system. While installing a global module, npm processes package.json of that module and looks for bin field. bin field is an object with key being the

--

--