Skip to content
Related Articles

Related Articles

Node.js prompt.get() Method

View Discussion
Improve Article
Save Article
  • Difficulty Level : Hard
  • Last Updated : 15 Oct, 2020

The prompt.get() method is an asynchronous function. This method takes strings representing property names in addition to objects for complex property validation (and more). This function is used for I/O operations.


prompt.get([object]/[properties name], callbackfunction)

Parameters: This method takes two parameters as shown below:

  1. [object]/[properties name]: This parameter holds the property of the input value or predefined object.
  2. callbackfunction: This parameter holds the callback function to make this function an asynchronous function.

Installation Module:

  1. You can visit the link to Install this module. You can install this package by using this command.

    npm install prompt
  2. After that, you can just create a folder and add a file for example, index.js. To run this file you need to run the following command.

    node index.js

Filename: Index.js

var prompt = require('prompt');
// Function call
// Reading two properties from user ie. name & class
prompt.get(['Name', 'class'], function (err, result) {
  // Printing the result
  console.log('Command-line input received:');
  console.log('Name: ' +;
  console.log('class: ' + result.class);

Project Structure:

Run the index.js file using the following command:

node index.js


prompt: name: some-user
prompt: class: 12th
Command-line input received:
name: some-user
class: 12th
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!