# prompt-async

> The enhanced prompt module that enables you to `await` its methods.

Latest version **0.9.9** (published 2017-10-23) · MIT license · 0 weekly downloads

## Install

```sh
npm install prompt-async
pnpm add prompt-async
yarn add prompt-async
bun add prompt-async
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.9.9 |
| Published | 2017-10-23 |
| First published | 2017-10-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=5.12.0 |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | K. |
| Maintainers | wlzla000 |
| Keywords | prompt, async, await, async-await, Promise, Promisify |

## Links

- npm: https://www.npmjs.com/package/prompt-async
- Repository: https://github.com/wlzla000/prompt-async
- Homepage: https://github.com/wlzla000/prompt-async#readme
- Issues: https://github.com/wlzla000/prompt-async/issues
- npm.io page: https://npm.io/package/prompt-async

## Dependencies (1)

- [prompt](https://npm.io/package/prompt.md) ^1.0.0

## Alternatives

- [promise-throttle](https://npm.io/package/promise-throttle.md) — 44.2K weekly downloads
- [@commercetools/sync-actions](https://npm.io/package/@commercetools/sync-actions.md) — 25.1K weekly downloads
- [cwait](https://npm.io/package/cwait.md) — 21.4K weekly downloads
- [@ledgerhq/hw-app-cosmos](https://npm.io/package/@ledgerhq/hw-app-cosmos.md) — 4.2K weekly downloads
- [@financial-times/o-loading](https://npm.io/package/@financial-times/o-loading.md) — 2.8K weekly downloads

## Recent versions

- 0.9.9 (latest) — 2017-10-23

## README

# [prompt-async](https://www.npmjs.com/package/prompt-async)

The **enhanced** [`prompt`](https://www.npmjs.com/package/prompt) module that enables you to [**`await`** its methods](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/async_function).

## Example <sup>[Try it now!](https://runkit.com/npm/prompt-async)</sup>

##### With [`prompt-async`](https://www.npmjs.com/package/prompt-async)

```javascript
const prompt = require("prompt-async");

async function example_async() // Available only with `prompt-async`!
{
	// Start the prompt.
	prompt.start();

	// Get two properties from the user: the `username` and `email`.
	const {username, email} = await prompt.get(["username", "email"]);
	// Get two properties from the user: the `password` and `food`.
	const {password, food} = await prompt.get(["password", "food"]);

	// Log the results.
	console.log("Command-line input received: ");
	console.log(`  username: ${username},`);
	console.log(`  password: ${password},`);
	console.log(`  email: ${email},`);
	console.log(`  food: ${food}.`);
}

async function error_handling_async()
{
	try
	{
		await example_async();
	}
	catch(error)
	{
		console.error("An error occurred: ", error);
	}
}

error_handling_async();
```

##### The obsolete way <sub>(causes a [_callback hell_](http://callbackhell.com))</sub>

```javascript
const prompt = require("prompt-async");

function example() // Still supports the obsolete way.
{
	// Start the prompt.
	prompt.start();

	// Get two properties from the user: the `username` and `email`.
	prompt.get(["username", "email"], (error, result1) => {
		if(error)
		{
			throw Error(error);
		}

		// Get two properties from the user: the `password` and `food`.
		prompt.get(["password", "food"], (error, result2) => {
			if(error)
			{
				throw Error(error);
			}

			// Log the results.
			console.log("Command-line input received: ");
			console.log(`  username: ${result1.username},`);
			console.log(`  password: ${result2.password},`);
			console.log(`  email: ${result1.email},`);
			console.log(`  food: ${result2.food}.`);
		});
	});
}

function error_handling()
{
	try
	{
		example();
	}
	catch(error)
	{
		console.error("An error occurred: ", error);
	}
}

error_handling();
```


## Frequently answered questions

### I've been working with [`prompt`](https://www.npmjs.com/package/prompt). Do I have to modify the existing code to use this?

**The only thing you have to do is to replace `require("prompt")` to `require("prompt-async")`.**
As you can see above, it has backward-compatibility, so it would work well with your `prompt` code.
However, please be aware that your `prompt` code pattern is discouraged, and try to use _`async`-`await`_ pattern.


## Any bugs, suggestions, or questions?

If you found a bug on it, or if you want to suggest something to improve it, or if you have a question,
please [leave an issue on the _GitHub_ repository](https://github.com/wlzla000/prompt-async/issues) or send an e-mail to me: `wlzla000@naver.com`.

**Feel free to contribute!**

Thank you.


## Licensed under

[the MIT license](https://github.com/wlzla000/prompt-async/blob/master/LICENSE).

---
_Source: https://npm.io/package/prompt-async · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
