https://github.com/practical-works/nodejs-cli
💻 Command line interface (CLI) example in NodeJS.
https://github.com/practical-works/nodejs-cli
cli command-line-interface command-line-tool node node-cli node-command-line node-commandline node-js nodejs nodejs-cli nodejs-command
Last synced: 2 months ago
JSON representation
💻 Command line interface (CLI) example in NodeJS.
- Host: GitHub
- URL: https://github.com/practical-works/nodejs-cli
- Owner: practical-works
- License: mit
- Created: 2021-09-19T03:29:41.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-09-19T18:08:48.000Z (almost 4 years ago)
- Last Synced: 2025-04-12T21:14:30.805Z (2 months ago)
- Topics: cli, command-line-interface, command-line-tool, node, node-cli, node-command-line, node-commandline, node-js, nodejs, nodejs-cli, nodejs-command
- Language: JavaScript
- Homepage:
- Size: 109 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 💻 NodeJS CLI
[](https://github.com/topics/web)
[](https://github.com/topics/javascript)
[](https://github.com/topics/node)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](https://github.com/tj/commander.js) library 😻.
## 🏁 Try it!
1. Clone the repository.
2. Stay in the parent folder of the project.
3. Execute the application:
```bash
node nodejs-cli
```
this will automatically execute the `index.js` file inside the `nodejs-cli` folder.
> **Output:** No options provided.4. Execute with some flags:
- _Help_ flag: `--help`
```bash
node nodejs-cli --help
```
> **Output:** This is an example cli app with nodeJS..- _Help_ flag alias: `-h`
```bash
node nodejs-cli -h
```
> **Output:** This is an example cli app with nodeJS..- _Name_ flag with parameter: `--name` or `-n`
```bash
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](./LICENSE).