Skip to content
Related Articles

Related Articles

Node.js prompt.addProperties() Method
  • 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.

Syntax:

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
    

Project:

Filename index.js

filter_none

edit
close

play_arrow

link
brightness_4
code

const prompt = require('prompt');
  
// Start the prompt
prompt.start();
  
// 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
    console.log(user);
  
});

chevron_right


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

node index.js

Input:

gfg112@gmail.com
prompt: age: 12

Output:

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