Last active
April 10, 2025 14:49
-
-
Save marcogrcr/9bb43c35819be66692471b01105e0a56 to your computer and use it in GitHub Desktop.
Confirms a y/n in a CLI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createInterface } from "node:readline"; | |
const rl = createInterface({ input: process.stdin, terminal: false }); | |
process.stdout.write("Please confirm with y/n: "); | |
for await (const line of rl) { | |
if (line === "y") { | |
break; | |
} | |
if (line === "n") { | |
process.exit(0); | |
} | |
process.stdout.write("Invalid input. Please confirm with y/n: "); | |
} | |
rl.close(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment