So, I am working with node.js for consume one API of IBM Cloud. I have this code and with that, I can to visualize the response but, I need pass this "res.send" to HTML. So, how can I do it?
This is my code in Node.js. Thank you!
var express = require('express');
var path = require('path');
var app = express();
app.listen(2000, function () {
console.log(' Watson!');
});
//---------------
app.get('/', (req, res) => {
//-------------Watson
var ToneAnalyzerV3 = require('watson-developer-cloud/tone-analyzer/v3');
var tone_analyzer = new ToneAnalyzerV3({
username: '',
password: '',
version_date: '2017-09-21',
accept_language: 'es',
tone_name: 'es'
});
var params = {
'tone_input': require('./tone.json'),
'content_type': 'application/json',
'content_language' : 'en',
'accept_language' : 'es'
};
tone_analyzer.tone(params, function(err, response) {
if (err){
console.log('error:', err);
res.send(err);
}
else{
res.render('index.html');
res.send({"Hi! I'm Waton and I can see:":response.document_tone.tones[0].tone_name});
console.log(JSON.stringify(response, null, 2));
}
});
});
I think you want this format which renders the view and pass the local variable to the view
Here's a good example