Create native prompts with Node.js and Electron
While alert
and confirm
are both supported in Electron, prompt
isn't (see this issue). native-prompt
aims to fix this by allowing you to create prompt boxes that are native to the user's OS. As an added bonus, it also works in Node.js.
Through NPM:
npm i native-prompt
npm install native-prompt@latest --save
prompt (title, body, options)
The title you want to display at the top of the window
Any helpful text to go inside the message box
Any (optional) extra options (see below)
The text you want to already be in the input box beforehand
Whether you want the box to have a hidden input
const prompt = require('native-prompt')
import prompt from 'native-prompt'
(async () => {
const text = await prompt("This is a title.", "What would you really like to see next?", { defaultText: "Nothing" });
if (text) {
// Do something with the input
} else {
// The user either clicked cancel or left the space blank
}
})()
prompt("This is a title.", "What would you really like to see next?", { defaultText: "Nothing" }).then(text => {
if (text) {
// Do something with the input
} else {
// The user either clicked cancel or left the space blank
}
})
(async () => {
const password = await prompt("Login", "Enter your password to log back in.", { mask: true });
if (isCorrectPassword(password)) {
// Log the user in
} else {
// The user's entered their username or password incorrect
}
})()