I'm using commander.js to run a program that keeps Node running (watching for files and running tasks).
It seems like Commander is waiting until the command exits to log any output. Is there a way to log output to the console while the command is running?
import { program } from 'commander';
import chokidar from 'chokidar';
program
.command('dev')
.description('Start the development server')
.action(async (options, command) => {
// Doesn't get logged unless program exits
console.log(`...`);
chokidar.watch('...')
});
// This also won't log until command is finished
process.stdout.write('...')
program.parse();
Commander does not modify the behaviour of
console.log
orprocess.stdout.write
, so the problems with the delayed output are something other than Commander.Note: you should be calling
program.parseAsync()
since you have an async action handler, but that isn't the solution to your problem.(Disclaimer: I am a maintainer of Commander.)