I had been coding a webapp and in his backend there's a function to create users. I need to use the values that are returned by that function, but how can I handle those values?
The function code:
module.exports = function(username, socialname, password) {
var hash = "PASSWORD";
var userId = nanoid(8);
var sucessMessage = {
sucesso: true,
message:"User created",
userId: userId
}
return sucessMessage; // Returning undefined when the function is displayed on console
};
And in mine server.js
file, where I'm handling the function:
module.exports.userCreate = function (username, socialname, password) {
userCreate(username, socialname, password);
};
So, in the index.js
I want to catch that returning value and display it on the console, how can I do that?
app.post("/user/create", (req, res) => {
var username = req.body.username;
var socialname = req.body.socialname;
var password = req.body.password;
const createdUser = userCommands.userCreate(username, socialname, password);
console.log(createdUser ) // undefined
});