2. Install the Earth Engine client library

The client library can be installed from npm with the following command:

npm install --save @google/earthengine

Once installed, the client library is placed within the current
project directory: node_modules/@google/earthengine/*. On future
projects, install the client in the same way.

3. Use the client library in an application

Within your application code, require the Earth Engine API:

var ee = require('@google/earthengine');

Uninstalling the client library

To uninstall using the npm package manager, run the following command:

npm uninstall --save @google/earthengine

This removes node_modules/@google/earthengine from the current project, but
does not affect any projects in other directories on the same machine.

Setting Up Authentication Credentials

Earth Engine APIs use the OAuth 2.0 protocol for
authenticating browser-based clients. For server-side authentication in Node.js, service
accounts are recommended. Web apps may use either approach, with pros and cons discussed
below.

Client-side authentication with OAuth

With client-side authentication in a web browser, users of your application log in with
their own Google accounts. These users must already be authorized to access Earth
Engine, and must have permission to read the assets used by your application.

Notice: Client-side authentication only works in the browser.
In server or command-line code, service account authentication is required.

Server-side authentication with a service account

With server-side authentication, a private key is stored with your application, allowing
it to access the Earth Engine API through a service account. Users of your application
do not need their own access to Earth Engine, and are not required to log in.

In Node.js, only server-side authentication is provided by the client library.

Caution: A private key gives an application permission to act
as your service account, and should be treated like a password. Never share a private
key or include it in version control. Instead, specify the private key using a config
file, or load it from an environment variable.

Testing the installation

To test that authentication has been set up correctly, run the following script:

If everything is installed correctly, the metadata for an image should be printed.

Notice: When using Earth Engine in a Node.js environment, some
best practices differ from typical scripts. Synchronous API calls should be avoided —
they prevent the app from handling other requests while waiting for a response from the
Earth Engine API. Instead, use asynchronous requests with callback functions. When using
the Earth Engine API in Google Cloud Functions, synchronous requests are not
supported.