I am new to Node Js trying to create an App translate fr to en. My code work fine when I use it in local node serve or firebase serve, but it didn't work on when i deploy it to Firebase Cloud function.
And also Firebase deploy run but didn't update google API as expected or the word not get translated , it shows "Pls wait" but din't update it Any help will be appreciated.
Firebase LOG - Error: getaddrinfo ENOTFOUND translate.google.com translate.google.com:443 at /user_code/node_modules/google-translate-api/node_modules/google-translate-token/index.js:103:25 at process._tickDomainCallback (internal/process/next_tick.js:135:7)
const functions = require('firebase-functions'); //in Firebase
const functions = require('firebase-functions');
const express = require('express');
var cors = require('cors')
const bodyParser = require('body-parser');
const app = express();
var translator = "Pls Wait";
const translate = require('google-translate-api');
app.use(bodyParser.json());
app.get('/api', function(req , res) {
createTranslation();
res.send(translator);
})
function createTranslation() {
translate('Ik spreek Engels', {to: 'en'}).then(res => {
console.log(res.text);
translator = res.text;
//=> I speak English
// players = res.text;
console.log(res.from.language.iso);
// return JSON.parse(res.body).data;;
//=> nl
}).catch(err => {
console.log("ERROR");
console.log(err);
console.error(err);
});
}
var server = app.listen(function(){
var host = server.address().address;
var port = server.address().port;
if(!host || host === "::"){
host = "localhost:";
}
console.log('API running on http://%s%s', host , port);
});
exports.app = functions.https.onRequest(app); //In Firebase