-2
Hello
I’m starting with NODE. I have the function below and would like it to return the translated text. Today she plays the text to the console. How do I get her to return the text? How would it look? Thanks.
function traduzirTexto() {
// ==> Aqui vamos configurar os requests
let options = {
method: 'POST',
baseUrl: endpoint,
url: 'translate',
qs: {
'api-version': '3.0',
'to': ['en', 'es']
},
headers: {
'Ocp-Apim-Subscription-Key': subscriptionKey,
'Content-type': 'application/json',
'X-ClientTraceId': uuidv4().toString()
},
body: [{
'text': 'Olá Desenvolvedor!'
}],
json: true,
}
// ==> Aqui vamos imprimir a nossa requisição
request(options, (err, res, body) => {
console.log(JSON.stringify(body, null, 4));
})
};
Guys I asked what would change the code to work, that’s all I wanted to know if anyone knew, to expedite a project here. I didn’t ask about where to get callback tutorials.
Do the job
traduzirTexto
receive a callback. This is necessary given the asynchronous nature of Javascript.– Luiz Felipe
It’s not clear to me yet.
– Marlon
This answers your question? What is a callback?, How asynchronous programming works in Javascript?, What are javascript (promises)?, and has more
– Costamilam