JAXA Earth API for JavaScript
    Preparing search index...

    Usage (for Node.js, Deno, Bun)

    JAXA Earth API for JavaScript can also run in the Node.js, Deno, and Bun JavaScript runtimes. Without setting up a complex environment for handling Earth observation data, you can visualize Earth observation data and save it as a PNG image, save it as a CSV file, or perform simple statistical processing.

    It supports both the ES Module (ESM) format and the CommonJS format. Use whichever suits your development approach.

    Note that, regarding image output, HTMLCanvasElement and OffscreenCanvas are not available in non-browser environments. Use createPng to output a PNG image.

    The content of this guide has been verified to work in the following runtimes (as of 2026.2). If it does not work, try a runtime newer than the following versions.

    • Node.js v22.20.0
    • Deno 2.1.9
    • Bun 1.2.2

    Download the module file from the following link.

    https://data.earth.jaxa.jp/api/javascript/v2.0.1/jaxa.earth.esm.js

    In addition, if you want to use code completion (IntelliSense) in VS Code and similar editors, or develop in TypeScript, use the following type definition file. It is applied automatically when saved in the same folder as jaxa.earth.esm.js.

    https://data.earth.jaxa.jp/api/javascript/v2.0.1/jaxa.earth.esm.d.ts

    Save them in any folder as shown below.

    - package.json
    - jaxa.earth.esm.js
    - jaxa.earth.esm.d.ts (Only if you want to use built-in code completion in tools like VS Code)
    - main.js

    When developing in the ESM format, write the following in package.json.

    {
    "type": "module"
    }

    Write the following in main.js.

    import * as je from "./jaxa.earth.esm.js";

    //Feature for file output (if Node.js is installed)
    import fs from "node:fs";

    //Retrieve the DataObject
    const dataObject = await je.getDataObject({
    collectionUrl: "https://s3.ap-northeast-1.wasabisys.com/je-pds/cog/v1/JAXA.EORC_ALOS.PRISM_AW3D30.v3.2_global/collection.json",
    band: "DSM",
    width: 1000,
    height: 500,
    bbox: [-180, -90, 180, 90],
    onloading: (progress, dataObject) => {
    console.log(progress);
    },
    });

    //Create a color map
    const colorMap = new je.image.ColorMap({
    min: 0,
    max: 6000,
    colors: je.Colors.JET,
    });

    //Save as a PNG image
    const png = await je.image.createPng(dataObject, colorMap);
    fs.writeFileSync("image.png", png);

    //Save as a CSV file
    const csv = je.data.createCsv(dataObject);
    fs.writeFileSync("data.csv", csv, "utf8");

    //The save methods above can run in a Node.js environment, or in a Bun environment without Node.js installed.
    //In a Deno environment without Node.js installed, you can instead save using the following methods.
    //await Deno.writeFile("image.png", png);
    //await Deno.writeTextFile("data.csv", csv);

    For Node.js, you can run it with the following command.

    node main.js
    

    For Deno, you need to grant access permissions for network and file operations, so use options as shown below.

    deno -A main.js
    

    For Bun, you can run it with the following command.

    bun main.js
    

    When execution succeeds, the results are saved as image.png and data.csv in the same folder.

    Download the module file from the following link. The Universal Module Definition (UMD) format module can also be used in a CommonJS-format development environment.

    When developing in the CommonJS format, write the following in package.json.

    {
    "type": "commonjs"
    }

    Write the following in main.js.

    //Import the module with require.
    const je = require("./jaxa.earth.umd.js");

    //Since top-level await is not allowed in the CommonJS format, write it inside an immediately invoked function.
    (async function () {

    //Processing such as await je.getDataObject is the same as in the ESM format sample.

    })();

    JAXA Earth API for JavaScript communicates with the server where the data is stored in order to retrieve the data. If an SSL certificate error occurs due to the network configuration of a company or organization, you can add the following code at the very beginning of main.js as a way to temporarily bypass SSL certificate verification.

    process.env["NODE_TLS_REJECT_UNAUTHORIZED"] = "0";