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 isomorphic-fetch isomorphic-form-data

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

require("isomorphic-fetch");
require("isomorphic-form-data");

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

request("https://www.arcgis.com/sharing/rest/info")
  .then(response);

Demo - Express Application

Authentication

To access premium content and services without asking for user credentials, using a Proxy Service or App Login is typically the best approach.

Proxy Service

// no auth required
request(`https://utility.arcgis.com/usrsvcs/appservices/{unique}/rest/services/World/Route/NAServer/Route_World/solve`)

App Login

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

// url not accessible to anonymous users
const url = `https://route.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World`

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

Demo - batch geocoding

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

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

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