How do I return an object in Promise

Viewed 25

I'm using prompt module and cannot figure out how to return the 'prompts function' object value in then() to obj variable

const prompt = require("prompt");

prompt.start();

const prompts = () => new Promise((resolve, reject) => {
prompt.get(["email", "password", "name"], (err, contents) => {
    if (err) reject(new Error("Error!"));
    resolve(contents);
});
});

var obj = prompts()
.then(contents => {
    return contents;
})

console.log(obj);
0 Answers
Related