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.
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 rootAn example can be found in projection.js.
More information can be found in the Working with assets guide topic.
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.
You can find native ESM samples in the /native-esm folder.
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;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:
npm i- install the modulesnpm run build- run the build scriptnode test-projection.js- run the app and the output will be written to the terminal window.