Skip to content
Related Articles

Related Articles

Node.js prompt.addProperties() Method

View Discussion
Improve Article
Save Article
  • Difficulty Level : Expert
  • Last Updated : 25 Oct, 2020

The prompt.addProperties() method is an asynchronous function and this method is used to add properties to an existing object from the command line. This function is used for I/O operations.


prompt.addProperties(object, Array[keys], callbackfunction)

Parameters: This method takes three parameters as shown below:

  1. object: The first parameter is an object which is predefined in the program.
  2. Array: The second parameter is the keys to the given object.
  3. callback function:  callback function to make this function is 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

const prompt = require('prompt');
// Start the prompt
// Create an object
const user = {
    name: 'GFG',
    country: 'India'
// Extending the `user` object
prompt.addProperties(user, ['email', 'age'], (err, user) => {
    if (err) {
        throw err;
    // Printing modified object

Step to run this program:
Run the index.js file using the following command:

node index.js

prompt: age: 12


prompt: email:
prompt: age:  12
{ name: 'GFG', country: 'India', email: '', age: '12' }
My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!