Back to articles
From Zero to npm: How to Build and Publish Your First CLI Tool

From Zero to npm: How to Build and Publish Your First CLI Tool

via Dev.to JavaScriptWilson Xu

From Zero to npm: How to Build and Publish Your First CLI Tool Publishing a package to npm feels like a rite of passage for JavaScript developers. But most tutorials make it seem harder than it is — or skip the details that actually matter, like choosing the right package name, setting up the bin field, or handling ESM vs CommonJS. This guide walks you through building a real CLI tool and publishing it to npm in under 30 minutes. No boilerplate generators, no complex build toolchains. Just Node.js and a few good decisions. What We're Building We'll create greet-cli — a simple but complete CLI tool that generates personalized greeting messages. It's deliberately simple so we can focus on the publishing process , not the tool itself. By the end, you'll understand: How package.json fields map to npm behavior What the bin field actually does How to handle ESM modules in CLI tools How npm scopes and naming work What happens when you run npm publish Step 1: Project Setup mkdir greet-cli && c

Continue reading on Dev.to JavaScript

Opens in a new tab

Read Full Article
2 views

Related Articles