Easy Confirmation Prompt for Node.js CLI Script
Prompt the user if they'd like to continue when executing a Node.js script from the command line.
The tldr:
import { createInterface } from 'node:readline/promises'
import { exit, stdin, stdout } from 'node:process'
const rl = createInterface({ input: stdin, output: stdout })
const answer = await rl.question('You sure? (y/n) ')
rl.close()
if (answer.toLowerCase() !== 'y') exit(0)
That's it actually.
from DynamoDB (6.8ms) to HTML (0.22ms) in 7.0ms