Skip to content

Latest commit

 

History

History
 
 

README.md

ArcGIS API for JavaScript in Node.js

Integrating Node.js with @arcgis/core can be done by building the app with native ES modules in a supported Node version or by transpiling to CommonJS. This sample contains examples of both approaches.

Working with assets

For most local builds, the API's assets are pulled from the ArcGIS CDN at runtime and there is no need for additional configuration. However, when working with certain modules, Node.js may require configuring the API to manage the assets locally. The assets include images, web workers, web assembly and localization files. Be sure to set config.assetsPath so that the assets are correctly resolved, for example:

import esriConfig from '@arcgis/core/config.js';
esriConfig.assetsPath = "node_modules/@arcgis/core/assets"; // relative to when running in root

An example can be found in projection.js.

More information can be found in the Working with assets guide topic.

Polyfills

Because Node does not have a native fetch or abort-controller, you will need to load polyfills:

require("cross-fetch/polyfill");
require("abort-controller/polyfill");

An example can be found in the test-webmap.js file.

Native ESM samples

You can find native ESM samples in the /native-esm folder.

IdentityManager

You will also want to disable the IdentityManager using config.request so it doesn't attempt to load DOM-related JavaScript.

import esriConfig from "@arcgis/core/config.js";
esriConfig.request.useIdentity = false;

Commands

For a list of all available npm commands see the scripts in package.json.

To run a test app, execute these commands in a terminal window:

  1. npm i - install the modules
  2. npm run build - run the build script
  3. node test-projection.js - run the app and the output will be written to the terminal window.