function prompt
Jump to headingprompt(message?: string,defaultValue?: string,): string | nullShows the given message and waits for the user's input. Returns the user's input as string.
If the default value is given and the user inputs the empty string, then it returns the given default value.
If the default value is not given and the user inputs the empty string, it returns the empty string.
If the stdin is not interactive, it returns null.
Examples Jump to heading
Jump to heading
Example 1
Example 1
const pet = prompt("Cats or dogs?", "It's fine to love both!");
// Displays the user's input or the default value of "It's fine to love both!"
console.log("Best pet:", pet);
Parameters Jump to heading
optional
Jump to headingmessage: stringoptional
Jump to headingdefaultValue: stringReturn Type Jump to heading
string | null