P
IntermediateAll AIs

Build a Complete Node.js CLI Tool

Generates the complete structure of a professional Node.js CLI with Commander.js, polished UX (colors, spinners), configuration, error handling, tests and npm publishing.

Paste in your AI

Paste this prompt in ChatGPT, Claude or Gemini and customize the variables in brackets.

Tu es un expert Node.js et développement d'outils CLI. Aide-moi à créer un outil en ligne de commande complet.

**Objectif du CLI :** [OBJECTIF_CLI]
**Commandes souhaitées :** [COMMANDES] (ex: init, build, deploy, status)
**Runtime cible :** [RUNTIME] (Node.js 20+, Bun)
**Publication :** [PUBLICATION] (npm public, usage interne)

Génère :
1. **Structure du projet** : arborescence recommandée
2. **package.json** : configuration bin, scripts, dépendances (Commander.js ou alternative)
3. **Implémentation des commandes** : code pour chaque commande avec options et arguments
4. **UX du CLI** :
   - Messages d'aide clairs
   - Couleurs avec chalk (succès/erreur/info)
   - Spinners pour les opérations longues
   - Mode verbose/quiet
5. **Configuration** : fichier de config utilisateur (cosmiconfig pattern)
6. **Gestion des erreurs** : codes de sortie, messages explicites
7. **Tests** : stratégie de test pour CLI (vitest, child_process)
8. **Publication npm** : .npmignore, README, workflow de release

Fournis le code complet pour au moins 2 commandes.

Why this prompt works

The cosmiconfig pattern for configuration is an npm ecosystem standard often ignored by less experienced developers. Requesting explicit UX (colors, spinners, verbose modes) produces usable CLIs, not just functional ones. Exit codes are critical for integration into scripts and pipelines.

Use Cases

Creating an internal tool to automate team workflowPublishing an open-source npm CLI packageReplacing shell scripts with a maintainable CLI

Expected Output

Project structure, configured package.json, command code with UX (colors/spinners), error handling, cosmiconfig configuration, tests and npm publishing guide.

Learn more

Check the full skill on Prompt Guide to master this technique from A to Z.

View on Prompt Guide

📬 Get new prompts every week

Join our newsletter and never miss a prompt.