Gathering detailed insights and metrics for @squareboat/nest-console
Gathering detailed insights and metrics for @squareboat/nest-console
Gathering detailed insights and metrics for @squareboat/nest-console
Gathering detailed insights and metrics for @squareboat/nest-console
Create beautiful CLI commands in your NestJS Applications
npm install @squareboat/nest-console
Typescript
Module System
Node Version
NPM Version
61
Supply Chain
94.1
Quality
76.8
Maintenance
100
Vulnerability
86.9
License
TypeScript (89.65%)
JavaScript (10.35%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
59 Stars
57 Commits
6 Forks
3 Watchers
3 Branches
4 Contributors
Updated on Jul 10, 2025
Latest Version
1.1.4
Package Id
@squareboat/nest-console@1.1.4
Unpacked Size
56.70 kB
Size
12.15 kB
File Count
34
NPM Version
9.6.6
Node Version
18.16.0
Published on
Jun 18, 2023
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
3
Create beautiful CLI commands in your application. A simple NestJS CLI module, comes packaged with utilities.
Quick Setup - Quickly setup and configure your application
Utilities - Comes packed with utilities to let you easily interact and print.
Beautiful Commands - Creating a beautiful command is as easy as creating a simple injector.
To install the package, run
1npm install @squareboat/nest-console
OR
1yarn add @squareboat/nest-console
For NestJS v6.7.x, please use
npm install @squareboat/nest-console^0.0.7
Once the cli
file is copied, you need to open the cli
file and change the module that you need to pass in createApplicationContext
method.
If you are following the default project structure created by
nest
command. You don't need to do anything.
Once the added the correct module in cli
file, you need to import the ConsoleModule
from the package.
1import { Module } from "@nestjs/common"; 2import { ConsoleModule } from "@squareboat/nest-console"; 3import { AppController } from "./app.controller"; 4import { AppService } from "./app.service"; 5 6@Module({ 7 imports: [ConsoleModule], 8 controllers: [AppController], 9 providers: [AppService], 10}) 11export class AppModule {}
Now, whatever command you create in your application will be discovered automatically.
To be able for the package to discover the command, you need to register the Injectable class inside
providers
property in your module.
There are basically two ways through which you can define commands.
Command
decorator on an Injectable classCommand
decorator on an Injectable class' method.Remember to use the
@Injectable
decorator on the class always a, else the command will not be discovered and registered.
You can create an injectable class and use @Command
decorator on it. The package will automatically look for handle
method inside the class.
You can use @Command
decorator on the method.
1import { Injectable } from "@nestjs/common"; 2import { Command, ConsoleIO } from "@squareboat/nest-console"; 3 4@Injectable() 5export class AppService { 6 @Command("hello {name=world}", { desc: "Test Command" }) 7 sayHello(_cli: ConsoleIO) { 8 const name = _cli.argument<string>("name"); 9 _cli.info(`Hello ${name}!`); 10 return; 11 } 12}
Before running the command, you need to build it first.
1npm run build
Now, to run any command, you can simply do
1node cli hello
We understand that you may want to build commands which can be dynamic in nature, ie. you may expect some required or optional parameters from client while running the command. We have made it dead simple for you to define your input expectations.
All user supplied arguments and options are wrapped in curly braces.
Arguments in console applications are required variables.
1@Command( 2 'generate:report {type}', 3 { desc: 'Test Command' } 4)
1$ node cli generate:report gar
Options are the optional inputs for each command. They are denoted by double hyphens (--
).
Example:
1@Command( 2 'generate:report {type} {--emails}', 3 { desc: 'Test Command',} 4)
1$ node cli generate:report gar --emails=email@example.com
To pass array of values in any options or arguments, you can add asterik.
1generate:report {type*} {--emails*}
1$ node cli generate:report gar gmr --emails=email@example.com --emails=email2@example.com
You can also define default values for the arguments or options by adding a =
equal sign followed by the value.
1generate:report {type=gar} {--emails=email@example.com}
We provide easy to use APIs to work with I/O directly from the console.
While executing command, you will need to fetch the values that you may have passed in the invocation. Your method will be passed an _cli: ConsoleIO
object. You can then simply check for all the values.
For fetching an argument, you can do
1const type = _cli.argument<string>("type");
For fetching an option, you can do
1const email = _cli.option<string>("email");
If no value is passed, the argument
and option
function will return the default value or null
value.
You may want to ask for input while executing a command. We provide several ways with which you can ask for inputs directly on console.
To ask for simple input from the user, you can call ask(question: string)
method.
1const name = _cli.ask("name");
You may want to ask user about some secret or any password, which ideally should not get printed on the console.
1const password = await _cli.password("Enter your pasword to continue");
While running a command, you can also give choices to select from a defined list. For example:
1/** 2 * Single choice example. 3 * Returns one of the passed choices. 4 */ 5const choice = await _cli.select( 6 "Please select one superhero", // question 7 ["Batman", "Ironman"], // choices 8 false // multiple? 9); 10 11/** 12 * Multiple choices example. 13 * Returns an array of the selected options. 14 */ 15const choice = await _cli.select( 16 "Please select one superhero", 17 ["Batman", "Ironman"], 18 true 19);
Lastly, sometimes you may want to ask for confirmation from the user before doing any execution. You can do so by using confirm
method.
1const confirm = await _cli.confirm("Do you really wish to continue?"); 2if (confirm) { 3 // do your magic here 4}
Till now, we have seen how we can operate with differnt type of inputs on the cli. There will be scenarios when you will want to print something on the console. We provide a very easy-to-use set of APIs for your basic console outputing needs.
To print any message on the console, use info
method
1_cli.info("Some amazing message"); // Outputs 'Some amazing message' on the console
Incase of an error message, use error
method.
1_cli.error("Oops! Something went wrong.");
Similarly, to print any success message, use success
method
1_cli.success("Wohoo! The command worked just fine!");
To print a divider on the console, simple do
1_cli.line();
To print a table on the console, you can use table
method:
1// this will automatically print unicode table on the console 2_cli.table([ 3 { name: "User 1", designation: "Software Engineer L1" }, 4 { name: "User 2", designation: "Software Engineer L1" }, 5]);
We provide few commands, which will help in your day to day development process.
To list all commands available in your application, you can do
1node cli list
list
is a reserved command name, please don't use it in any of the commands
We provide few out-of-the-box predefined options, which you can use with each of your command.
To list all the arguments and options that your command supports/expects, simply run
1node cli users:greet --options
--options
is a reserved option. Please don't use it anywhere in your command
To know about contributing to this package, read the guidelines here
We are a bunch of dreamers, designers, and futurists. We are high on collaboration, low on ego, and take our happy hours seriously. We'd love to hear more about your product. Let's talk and turn your great ideas into something even greater! We have something in store for everyone. ☎️ 📧 Connect with us!
We are hiring! Apply now at careers page
The MIT License. Please see License File for more information. Copyright © 2020 SquareBoat.
Made with ❤️ by Squareboat
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
1 existing vulnerabilities detected
Details
Reason
3 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 2
Reason
Found 3/25 approved changesets -- score normalized to 1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More