I'm trying to develop a nodejs app that uses Google earth engine for some geospatial data analisys. I'm using "@google/earthengine": "^0.1.185", node v16.4.2 and npm v 7.18.1. I also created the service account with gcloud and followed the step by step Google Earth Engine npm installation. The problem is, everytime I call some earth engine feature it just give the error:
throw ee.initializationFailure_(e), e;
^
Error: Failed to contact Earth Engine servers. Please check your connection, firewall, or browser extension settings
before I just got 404 error when trying to connect to earth engine. I tried to deactivate my firewall as well as change the internet I was using, still the same. See the code down and the error:
const ee = require('@google/earthengine');
const path = require("path");
const express = require('express');
const app = express();
const privateKey = require('./privatekey.json');
const port = process.env.PORT || 4000;
app.set('views', __dirname + '/views');
//app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "html");
app.get('/', (_,res)=>{
res.sendFile('index.html', {root : __dirname + '/views'});
});
// Define endpoint at /mapid.
app.get('/mapid', (_, response) => {
// Instantiate an image with the Image constructor.
var image = ee.Image('CGIAR/SRTM90_V4');
// Zoom to a location.
Map.setCenter(-112.8598, 36.2841, 9); // Center on the Grand Canyon.
// Display the image on the map.
Map.addLayer(image);
});
console.log('Authenticating Earth Engine API using private key...');
ee.data.authenticateViaPrivateKey(
privateKey,
() => {
console.log('Authentication successful.');
ee.initialize(() => {
console.log('Earth Engine client library initialized.');
app.listen(port);
console.log(`Listening on port ${port}`);
},
(err) => {
console.log(err);
});
},
(err) => {
console.log(err);
});
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
the error
C:\blablablabla\node_modules\@google\earthengine\build\main.js:17724
throw ee.initializationFailure_(e), e;
^
Error: Failed to contact Earth Engine servers. Please check your connection, firewall, or browser extension settings.
at Object.ee.data.handleResponse_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15467:9)
at Object.ee.data.send_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15390:18)
at Object.ee.data.getAlgorithms (C:\blablablabla\node_modules\@google\earthengine\build\main.js:14670:24)
at Function.ee.ApiFunction.initialize (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15923:78)
at Object.ee.initialize (C:\blablablabla\node_modules\@google\earthengine\build\main.js:17722:26)
at blablablabla\app.js:36:10
at Object.ee.data.handleAuthResult_ (C:\blablablabla\node_modules\@google\earthengine\build\main.js:15497:16)
at blablablabla\node_modules\@google\earthengine\build\main.js:14490:19
at blablablabla\node_modules\@google\earthengine\build\main.js:14424:41
at blablablabla\node_modules\google-auth-library\lib\auth\jwtclient.js:119:5
please I really need your help.