Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
press-any-key
Advanced tools
An utility to launch the simplest confirmation dialog.
npx press-any-key
Press any key to continue...
If user presses any key it will exit with code 0. In the case of pressing CTRL+C it will exit with code 1.
If you wish to use the utility from a npm scripts, you can install it into your project as a usual npm dependency.
npm install press-any-key --save-dev
But you can also use npx to invoke the command without install.
npx press-any-key
press-any-key <message> [...options]
By the default, the message is "Press any key to continue..."
, but if you would like you can specify your own message as the first argument.
press-any-key "Press any key to run the application"
Options:
--ctrlc <code>
Exit code on pressing CTRL-C.
--preserve-log
Do not clean the message, after resolve
You can use standard bash logical operators &&
and ||
to perform branching.
npx press-any-key && echo "A good choice!" || echo "Bye bye :("
Or you can rely on the fact that CTRL + C, by default, exits the process.
For example, you have a script that performs irreversible actions, and to avoid accidental execution of the script, you can add additional confirmation.
echo 'You are about to delete all files in current directory'
npx press-any-key
rm -rf *
You are about to delete all files in the current directory
Press any key to continue...
You can use the package press-any-key API in your node.js script.
const pressAnyKey = require('press-any-key');
pressAnyKey()
.then(() => {
// ... User presses a key
})
pressAnyKey(message, options)
The message is a string that will be displayed in standard output, before it starts to listen for key pressing. Pass null
if you'd like to use default message.
Options:
ctrlC
The exit code, or "reject"
(do reject the promise), or false to perceive as pressing any key.preverseLog
Preserve the message in the logBy the default when user presses CTRL+C the function will exit the process. But you able to change the standart behavior of CTRL+C by passing option ctrlC
with the value "reject"
. In this case, pressing CTRL+C wont exit the process, but do reject the promise.
const pressAnyKey = require('press-any-key');
pressAnyKey("Press any key to resolve, or CTRL+C to reject", {
ctrlC: "reject"
})
.then(() => {
console.log('You pressed any key')
})
.catch(() => {
console.log('You pressed CTRL+C')
})
Vladimir Kalmykov vladimirmorulus@gmail.com
MIT
FAQs
Press any key to continue...
The npm package press-any-key receives a total of 15,323 weekly downloads. As such, press-any-key popularity was classified as popular.
We found that press-any-key demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.