Node.js CLI with Inquirer
Build an interactive CLI tool in Node.js using Inquirer for prompts, chalk for colored output, and ora for spinners. Includes command chaining, template.
Code
import inquirer from 'inquirer';
import chalk from 'chalk';
import ora from 'ora';
const answers = await inquirer.prompt([
{ type: 'input', name: 'name', message: 'Project name:' },
{ type: 'list', name: 'framework', choices: ['react', 'vue', 'svelte'], default: 'react' },
{ type: 'confirm', name: 'ts', message: 'Use TypeScript?', default: true },
]);
const spinner = ora('Scaffolding...').start();
await scaffold(answers);
spinner.succeed(chalk.green(`Created ${answers.name}`));