Get Started with Node.js

Make sure you have polyfills for fetch and FormData installed before using any ArcGIS REST JS library. You can find npm install commands for all packages in the API reference.

npm install @esri/arcgis-rest-request @esri/arcgis-rest-auth cross-fetch isomorphic-form-data

Require cross-fetch and isomorphic-form-data before using any of the ArcGIS REST JS methods.

// ensures fetch is available as a global

const { request } = require("@esri/arcgis-rest-request");

  .then(response => console.log(response));

Or, if using NodeJS version v13 or higher, if you set "type": "module" in the package.json you can use ES Modules import syntax:

import fetch from "node-fetch";
import FormData from "isomorphic-form-data";
import arcgisRestRequest from "@esri/arcgis-rest-request";
arcgisRestRequest.setDefaultRequestOptions({ fetch, FormData });

  .then(response => console.log(response));

You can also pass through your own named fetch implementation.

const fetch = require("node-fetch")
const {
} = require("@esri/arcgis-rest-request");

// one by one
request("", { fetch })

// or in *every* request
setDefaultRequestOptions({ fetch })

Demo - Express


To access premium content and services without asking for user credentials, using an API key or application credentials is typically the best approach.


// no auth required

Application credentials

const { ApplicationSession } = require("@esri/arcgis-rest-auth");

const authentication = new ApplicationSession({
  clientId: "public",
  clientSecret: "secret"

// url not accessible to anonymous users
const url = ``

// token will be appended by rest-js
request(url, {

Demo - batch geocoding

Applications cannot create, share, access or modify items in ArcGIS Online or ArcGIS Enterprise. For this, a UserSession is more appropriate.

const { UserSession } = require("@esri/arcgis-rest-auth");

// hardcoded username / password
const authentication = new UserSession({
  username: "jsmith",
  password: "123456"

See the Browser Authentication for more information about implementing OAuth 2.0.