Skip to content

πŸ’» Command line interface (CLI) example in NodeJS.

License

Notifications You must be signed in to change notification settings

practical-works/nodejs-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ’» NodeJS CLI

Web JavaScript NodeJS

Simple Command line interface (CLI) application example in NodeJS.

This is a simple example that shows how you can natively play around with the NodeJS command arguments. If you want a complete solution for building NodeJS CLI applications, I'd suggest you go for the Commander library 😻.

Screenshot

🏁 Try it!

  1. Clone the repository.

  2. Stay in the parent folder of the project.

  3. Execute the application:

node nodejs-cli

this will automatically execute the index.js file inside the nodejs-cli folder.

Output: No options provided.

  1. Execute with some flags:
  • Help flag: --help
node nodejs-cli --help

Output: This is an example cli app with nodeJS..

  • Help flag alias: -h
node nodejs-cli -h

Output: This is an example cli app with nodeJS..

  • Name flag with parameter: --name or -n
node nodejs-cli --name Ambratolm

Output: Hello, Ambratolm! Welcome! :D

πŸš€ Features

  • Execute command options through flags (arguments prefixed with "--") with aliases (arguments shorthands prefixed with "-").
  • If flags are duplicate or merged with their aliases it executes the associated command one time only.
  • Prompts unknown flags.
  • To add a new option flag, just add a method in the actions/@methods.js file.
  • To add an alias for a flag, just add an entry in actions/@aliases.js file with the name of the targeted method as the key and an array of aliases as the value.

πŸ“ƒ License

Licensed under MIT.