I have the following problem, which I think is very simple, but I am very new to node, so I still have problems with these things.
I have a .js file that connects to an external service and makes use of (res and req) and returns it as json.
What I need is to return that result inside a variable in another .js file
I'll give you an example so you can understand me.
export function getConversation( req, res) {
// Getting workspace credentials from mongo
//connectToConversation('req.body.conversationName');
//console.log(input);
connectToConversation('Courtesy'); //Business
conversation = new Conversation({
username: CurrentConversation[0]['username'],
password: CurrentConversation[0]['password'],
url: '',
version_date:
});
console.log(req.body.context);
var workspace = CurrentConversation[0]['workspaceID'];
//var workspace = '';
if (!workspace) {
return res.json({
'output': {
'text': ''
}
});
}
console.log(CurrentConversation[0]['workspaceID']);
var payload = {
workspace_id: workspace,
input: req.body.input || {}
};
conversation.message(payload, function(err, data) {
if (err) {
return res.status(err.code || 500).json(err);
}
return res.json(updateMessage(payload, data));
});
}
I need to use that function from another file.js and send the result to it.
I know the problem is simple, sorry for bothering.
Thank you.