Skip to main content Link Menu Expand (external link) Document Search Copy Copied

Prompts API doc

The inner prompts API is exposed to prepend/append transform, and “before” and “after” tasks.

prompts.text

Use async/await syntax.

const userProvidedText = await prompts.text({message: 'Can you provide some text?'});

Or use traditional promise API.

prompts.text({message: 'Can you provide some text?'}).then(
  userProvidedText => {

  },
  err => {
    // aborted, user hit "ESC" key.
  }
);

Unlike the text prompt options in questions, you don’t need name in the options. This API prompts.text() directly returns user input without the need to wrap it into an object {'field-name': 'user input'}.

You can supply additional options default, validate you saw in questions.

prompts.select

Use async/await syntax.

const result = await prompts.select({
  message: 'Can you choose one of these?',
  choices: [
    {value: 'a', title: 'Something'},
    {value: 'b', title: 'Another thing'}
  ]
});
// result is either 'a' or 'b';

Or use traditional promise API.

prompts.select({
  message: 'Can you choose one of these?',
  choices: [
    {value: 'a', title: 'Something'},
    {value: 'b', title: 'Another thing'}
  ]
}).then(
  result => {
    // result is either 'a' or 'b';
  },
  err => {
    // aborted, user hit "ESC" key.
  }
);

Multi-select

Use async/await syntax.

const result = await prompts.select({
  multiple: true,
  message: 'Can you choose one or more of these?',
  choices: [
    {value: 'a', title: 'Something'},
    {value: 'b', title: 'Another thing'}
  ]
});
// result can be [], or ['a'], or ['b'], or ['a', 'b']

Or use traditional promise API.

prompts.select({
  multiple: true,
  message: 'Can you choose one or more of these?',
  choices: [
    {value: 'a', title: 'Something'},
    {value: 'b', title: 'Another thing'}
  ]
}).then(
  result => {
    // result can be [], or ['a'], or ['b'], or ['a', 'b']
  },
  err => {
    // aborted, user hit "ESC" key.
  }
);