Node.js prompt.addProperties() Method
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:
- object: The first parameter is an object which is predefined in the program.
- Array: The second parameter is the keys to the given object.
- callback function: callback function to make this function is an asynchronous function.
Installation Module:
- You can visit the link to Install this module. You can install this package by using this command.
npm install prompt
- 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
const prompt = require( 'prompt' );
prompt.start();
const user = {
name: 'GFG' ,
country: 'India'
};
prompt.addProperties(user, [ 'email' , 'age' ], (err, user) => {
if (err) {
throw err;
}
console.log(user);
});
|
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' }
Share your thoughts in the comments
Please Login to comment...