Patrones de diseño en Node.js
Qué es Node.js y cómo impulsa tu negocio
Patrones de diseño esenciales en Node.js
Patrón Singleton y Factory en JavaScript
Implementación práctica de Singleton y Factory en JavaScript
Implementación del patrón Observer con EventEmitter en Node.js
Implementación de Middlewares en Node.js sin Express
Decorators e inyección de dependencias en JavaScript
Flujo de Datos con Node.js
Aprende qué son Buffer y Streams en Node.js
Cómo utilizar streams y pipelines en Node.js
Cómo funciona el Event Loop en Node.js
Qué es Libuv y cómo maneja la asincronía en Node.js
Estrategias para ejecutar código asíncrono en Node.js
Debugging y Diagnóstico en Node.js
Cómo utilizar el Debugger en Node.js para solucionar problemas
Uso de Diagnostic Channels en Node.js para observabilidad y diagnóstico
Instrumentación y métricas clave en performance para aplicaciones Node.js
Control de errores globales y manejo de señales en Node.js
Implementación Eficiente de Logs con Pino en Node.js
Performance en Node.js
Análisis del event loop en aplicaciones Node.js usando Nsolid
Cómo Diagnosticar y Solucionar Memory Leaks en Aplicaciones Node.js
Optimizar rendimiento en Node.js con Worker Threads y Child Processes
Optimiza y Escala Aplicaciones Node.js con Técnicas de Caching
Creando CLIs con Node.js
Cómo crear aplicaciones CLI con Node.js
Cómo Crear un CLI con Minimist y Manejar Argumentos en Node.js
Creación de un CLI con Node.js y Google Generative AI
Creación de Chat con IA usando CLI en Node
Cómo Crear e Instalar tu Propio CLI de Node con npm
You don't have access to this class
Keep learning! Join and start boosting your career
Creating your own command line interface(CLI) in Node.js and being able to use it from anywhere in the system provides agility and efficiency to your workflow. Learn the key steps to transform your CLI into a binary and easily install it on your machine using npm.
Essentially, the first thing is to edit your package.json
file. Here, after the existing scripts section, you will add a new section called bin. This section will explicitly specify the name of the command and the file it will execute when invoked.
Be sure to follow these steps:
platzi-assistant
.ai-assistant
.Your package.json
file should look similar to this:
{ "bin": { "platzi-assistant": "ai-assistant" }}
Once you have configured your package.json
file, you are ready to install your CLI locally, for which you will use the npm link command.
Follow these simple steps:
package.json
file.npm link
After running this command, you will be able to use platzi-assistant
from anywhere in your terminal without needing to be in a specific directory.
Don't forget that if your CLI requires an API key, such as the one mentioned for Gemini, you must make sure to set it before use.
Publishing your CLI package in npm allows you to use it globally or run it easily with npx without prior installations. You can install globally published packages by:
npm install -g package-name
Or run them temporarily without installation using the npx command:
npx package-name
Exploring npm publishing can take the usability of your creations to another level. Consider checking out the specialized npm publishing course Platzi has available if you want to delve deeper into these topics.
Do you have creative ideas for useful CLI commands that you can develop? Share them in comments and encourage others to use them and contribute!
Contributions 0
Questions 0
Want to see more contributions, questions and answers from the community?