A lightweight CLI tool and Node.js module for formatted console output.
- π¨ Rich formatting for messages (success, error, warning, info, headers)
- π Verbose mode for detailed logging
- π Quiet mode to suppress non-essential output
- π Spinner for showing progress during async operations
- π Usable via CLI or programmatically in Node.js
- π Structured output for better readability
- π Ideal for CI/CD, automation scripts, and development tools
npm install -g @sp-packages/printer
This allows you to use printer
globally in your terminal.
npm install @sp-packages/printer --save-dev
Then, run it via:
npx printer success "Setup completed!"
printer <type> <message>
- β
success
- Green message for success output - β
error
- Red message for errors (supports error objects) - β
warning
- Yellow message for warnings - βΉ
info
- Blue message for general information - π
message
- Plain text message (no formatting)
printer success "Operation completed successfully!"
printer error "Something went wrong"
printer warning "This is a warning message"
printer info "Starting process..."
printer message "Simple message without formatting"
You can also use printer
inside your JavaScript/TypeScript projects.
import { Printer } from '@sp-packages/printer';
Printer.success('Setup completed successfully!');
Printer.error('An error occurred', new Error('Database connection failed'));
Printer.warning('This is a warning message');
Printer.info('Fetching data...');
Printer.message('Regular message');
The spinner feature is perfect for displaying progress during asynchronous operations. It shows an animated loading indicator that can be updated with success or error states.
import { Printer } from '@sp-packages/printer';
const spinner = Printer.spinner('Loading data...');
// During async operations
try {
await someAsyncOperation();
spinner.succeed('Data loaded successfully!');
} catch (error) {
spinner.fail('Failed to load data!');
}
spinner.start()
- Start or restart the spinnerspinner.stop()
- Stop and clear the spinnerspinner.succeed(text?)
- Stop the spinner and show success statespinner.fail(text?)
- Stop the spinner and show failure statespinner.warn(text?)
- Stop the spinner and show warning statespinner.info(text?)
- Stop the spinner and show info state
Verbose mode provides detailed logging, which can be extremely helpful for debugging and development purposes. When enabled, it outputs additional information that can help you trace the execution flow and identify issues more easily.
Printer.enableVerbose();
Printer.log('This will display only in verbose mode.');
Printer.disableVerbose();
Printer.enableVerbose();
Printer.success('Process completed');
Printer.log('Detailed execution log...');
Output:
β
[SUCCESS] Process completed
Detailed execution log...
Printer.disableVerbose();
Printer.success('Process completed');
Printer.log('Detailed execution log...');
Output:
β
[SUCCESS] Process completed
- Enhanced Debugging: Verbose mode provides more context and detailed logs, making it easier to pinpoint where things might be going wrong in your code.
- Better Traceability: With more information being logged, you can trace the execution path and understand the sequence of operations.
- Improved Development Experience: Developers can get insights into the internal workings of the module, which can be particularly useful during development and testing phases.
- Efficient Troubleshooting: Detailed logs can help in quickly identifying and resolving issues, reducing the time spent on debugging.
- Single Control Point: Verbose mode can be enabled or disabled with a single flag, providing a centralized way to control the verbosity of logs.
Verbose mode is particularly useful in CI/CD pipelines, automation scripts, and during the development of complex Node.js applications where understanding the flow of execution is crucial.
Quiet mode suppresses all output, including errors. This can be useful when you need to ensure that no messages clutter the console output in production or automated environments.
Printer.enableQuiet();
Printer.disableQuiet();
Printer.enableQuiet();
Printer.success('Process completed');
Printer.warning('This warning will NOT be displayed');
Printer.error('Critical error!');
Output:
Note: When quiet mode is enabled, no messages will be printed, including errors.
Printer.disableQuiet();
Printer.success('Process completed');
Printer.warning('This warning WILL be displayed');
Output:
β
[SUCCESS] Process completed
β [WARNING] This warning WILL be displayed
β
[SUCCESS] Operation completed successfully!
β [ERROR] An error occurred: Database connection failed
β [WARNING] Be cautious! Proceeding with default values.
βΉ [INFO] Fetching data...
π [MESSAGE] Process initiated.
- CI/CD Pipelines β Enhance logs in automation scripts
- Node.js CLI Tools β Format console outputs for better readability
- Development Debugging β Enable verbose mode for debugging
- Project Setup Scripts β Display status messages during installations
Contributions are welcome! Please open an issue or submit a pull request on GitHub.
This project is licensed under the MIT License. See the LICENSE file for details.