Open zachleat opened 1 month ago
interesting Node.js pattern here: https://www.linkedin.com/posts/mapocock_til-you-can-prompt-folks-on-your-cli-without-activity-7255214390419894272-SXMi
import { stdin, stdout } from "node:process";
import { createInterface } from "node:readline/promises";
// 1. Create an interface, taking in stdin and stdout
const rl = createInterface({
input: stdin,
output: stdout,
});
// 2. Ask the user a question, and await the result!
const answer = await rl.question(
"How attractive is Matt Pocock? ",
);
// 3. Get access to the answer immediately
console.log(
`Thank you for your valuable feedback: ${answer}`,
);
// 4. Close the interface
rl.close();
Transcribed, because blind people should be able to learn as well :)
Node.js API documentation on the subject
I would expect some signal handling (Ctrl+C and friends). Perhaps best to have a try-catch around the question?
Node itself has a learning module with some recommendations on handling sensitive data. Keep in mind that the callback version should work better for larger data (because RAM limitations and streaming).
The ava test runner has a nice option to rerun tests with
r
and it’d be nice to have something similar in Eleventy (especially with incremental builds)