Skip to content
import config from "@arcgis/core/config.js";
Since
ArcGIS Maps SDK for JavaScript 4.0

Configure global properties of the library.

Note

It is recommended that properties of the config module be set on a global esriConfig variable before the API is loaded. Setting properties on the config module after the API is loaded may not have the intended effect, as some properties need to be set by the time the first request is made that needs that value. For example, the apiKey property needs to be set before the first request is made to a secure service that requires an API key. If the apiKey is set after that, the request will fail with an authentication error and prompt for credentials instead of using the API key.

Examples
// Load the config module and set the portalUrl property
const config = await $arcgis.import("@arcgis/core/config.js");
config.portalUrl = "https://myHostName.esri.com/arcgis";
<script>
// Use the global esriConfig variable to initialize properties
var esriConfig = {
portalUrl: "https://myHostName.esri.com/arcgis"
};
</script>

Variables

config

Variable
Type
Config

Type definitions

Config

Type definition

apiKey

Property
Type
string | null | undefined
Since
ArcGIS Maps SDK for JavaScript 4.18

An authorization string used to access a resource or service. API keys are generated and managed in your portal. An API key is tied explicitly to an ArcGIS account; it is also used to monitor service usage. Setting a fine-grained API key on a specific class overrides this global API key. This property is used to configure API keys for ArcGIS Online or ArcGIS Location Platform items/services.

Note

To configure a global API key for ArcGIS Enterprise items/services, use the apiKeys property.

See also

apiKeys

Property
Type
ApiKeysConfig
Since
ArcGIS Maps SDK for JavaScript 4.33

An object that contains global API keys for various services and scopes. This object can be used to configure API keys to access the basemap style service and/or secure ArcGIS Enterprise services/items. Alternatively, a fine-grained API key can be set on a specific class, which will override this global API key. See the API keys guide page for more information.

Note

To configure a global API key for ArcGIS Online or ArcGIS Location Platform items/services, use the apiKey property.

See also
Examples
// Set an API key for multiple services.
config.apiKeys.scopes = [
{
// The API key value.
token: "API_KEY_FOR_SERVICE",
// An array of URLs that the API key applies to.
urls: [portalURL, serverURL]
},
// More scopes can be added here...
];
// Set an API key for the basemap styles service
config.apiKeys.basemapStyles = "API_KEY_FOR_BASEMAP_STYLES";

applicationName

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 4.27

The name of the application using the API. This value is returned in the output of the GetEnvironment function in Arcade expressions.

Default value
""
Example
config.applicationName = "Sample Application";

assetsPath

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 4.18

Overrides the URL for loading the API assets when using local builds of the @arcgis/core npm package. The assets include styles, images, web workers, wasm and localization files. By default, assets are loaded from a CDN at runtime.

For use only in local npm builds.

See also
Default value
"https://js.arcgis.com/<jssdk-version>/@arcgis/core/assets"
Example
import config from "@arcgis/core/config";
config.assetsPath = "./assets";

fontsUrl

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 4.8

The URL for font resources used by the Font.family class in non-MapImageLayer labels for both 2D MapViews and 3D SceneViews. This also applies to TextSymbol, TextSymbol3DLayer, and renderPreviewHTML().

To use your own hosted fonts, the font files need to be in .pbf format for 2D, .woff2 format for 3D, and .woff2 format for renderPreviewHTML. You also must follow the kebab-case naming convention (e.g. "arial-unicode-ms-bold").

See also
Default value
"https://static.arcgis.com/fonts"
Example
config.fontsUrl = "https://myserver.com/fonts";

geoRSSServiceUrl

Property
Type
string

The URL for the utility service used by GeoRSSLayer to convert GeoRSS documents.

Default value
"https://utility.arcgis.com/sharing/rss"
Example
config.geoRSSServiceUrl = "https://servername.domain.suffix/arcgis/sharing/rss";

geometryServiceUrl

Property
Type
string

The default geometryService used by components and other operations, such as on-the-fly projections.

Default value
"https://utility.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer"
Example
config.geometryServiceUrl = "https://utility.arcgisonline.com/arcgis/rest/services/Geometry/GeometryServer";

kmlServiceUrl

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 4.5

The URL for the utility service used by KMLLayer to convert KML documents.

Default value
"https://utility.arcgis.com/sharing/kml"
Example
config.kmlServiceUrl = "https://servername.domain.suffix/arcgis/sharing/kml";

log

Property
Type
LogConfig
Since
ArcGIS Maps SDK for JavaScript 4.17

An object with properties that control various aspects of log messages.

Note that the module name, message and detailed content of log messages is not considered stable and interceptors should not be used to create application error handling control flows.

portalUrl

Property
Type
string

The default URL of new portal instances. If using an on-premise portal, this value should be set to the portal instance, for example: https://www.example.com/arcgis

See also
Default value
"https://www.arcgis.com"
Example
// Set the hostname to the on-premise portal
config.portalUrl = "https://myHostName.esri.com/arcgis"

request

Property
Type
RequestConfig

An object with properties that control various aspects of communication between the library and web servers.

See also

respectPrefersReducedMotion

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.30

Controls whether the API respects the user's preference for reduced motion. When set to true, animations will be minimized or disabled when the user has enabled the prefers-reduced-motion browser or operating system setting. When set to false, the API will ignore the prefers-reduced-motion setting, considering all animations essential.

The prefers-reduced-motion setting is a media feature that can be used to detect if the user has requested that the system minimize the amount of animation or motion it uses. This setting is useful for users who have vestibular disorders or other conditions that make animations problematic. For more information, see the prefers-reduced-motion documentation.

Known Limitations

Reduced motion preferences are only supported in 2D MapView at this time. 3D SceneView support is planned for a future release.

Default value
true
Example
// Ignore prefers-reduced-motion flag for all animations
config.respectPrefersReducedMotion = false;

routeServiceUrl

Property
Type
string
Since
ArcGIS Maps SDK for JavaScript 4.23

The default routing service used by the RouteLayer and the Directions component.

Default value
"https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World"
Example
config.routeServiceUrl = "https://route-api.arcgis.com/arcgis/rest/services/World/Route/NAServer/Route_World";

sessions

Property
Type
SessionsConfig | undefined
Since
ArcGIS Maps SDK for JavaScript 5.0

The configuration for sessions, which are used with an API key to manage user authentication and authorization with the API. When a session is created, it provides a short-lived session token that can be used to access ArcGIS services for the duration of the session. The API key can be set using the apiKey property or the apiKeys.basemapStyles property.

Sessions are only used with API keys that are generated from an ArcGIS Location Platform account.

userPrivilegesApplied

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.28

Indicates whether layers should apply privileges of the authenticated user to their capabilities.

Default value
true

workers

Property
Type
WorkersConfig

An object with properties that control various aspects of the workers framework.

Example
// Set the path for the worker's AMD loader configuration
// to a folder called workersFolder.
config.workers.loaderConfig = {
paths: {
myWorkers: new URL("./workersFolder", document.baseURI).href
}
};
// load myWorkers/Calculator.js in the workers framework
// and invoke its "getMaxNumber" method
workers.open(this, "myWorkers/Calculator")
.then((connection) => {
return connection.invoke("getMaxNumber", [0, 1, 2, 3, 4]);
})
.then((result) => {
console.log(result);
});
//*********************************************************
// module: workerFolder/Calculator.js
//*********************************************************
define([], () => {
return {
// this function can be invoked from the main thread
getMaxNumber: function (number) {
return Math.max.apply(null, numbers);
}
};
});

ApiKeysConfig

Type definition

basemapStyles

Property
Type
string | undefined

The API key for the basemap styles service. This should be set if loading a web map that uses a basemap style service. Otherwise, set a fine-grained API key on the BasemapStyle.apiKey class. If user authentication is not required in the application, the apiKey property can be set instead.

scopes

Property
Type
Array<ApiKeysScopeConfig> | undefined

An array of objects that define ArcGIS Enterprise API keys and their respective portal URLs.

ApiKeysScopeConfig

Type definition

token

Property
Type
string

The API key used to access a resource or service.

urls

Property
Type
RegExp | string | Array<RegExp | string>

The URL or multiple URLs to the resource and/or service that the API key was generated for. When accessing a secure layer (such as a FeatureLayer) that requires an API key, both the portal URL and server URL should be included in the urls array. If the value is type String, then it matches if the request URL starts with that string. If using a RegExp, the g and y flags should not be used.

WorkersConfig

Type definition

loaderUrl

Property
Type
string | undefined

The absolute url to the AMD or SystemJS loader used in the worker. The AMD CDN build has a default value for when this property isn't set. This is required when using custom workers. See this ESM sample.

workerPath

Property
Type
string | undefined

This is used by the @arcgis/core npm package to control where to load a custom build of the RemoteClient from. By default, RemoteClient is loaded from the API's assets. See this ESM sample.

loaderConfig

Property
Type
WorkersLoaderConfig | undefined

The AMD configuration object that is set in each worker.

WorkersLoaderConfig

Type definition

baseUrl

Property
Type
string | undefined

The AMD loader loads all code relative to the baseUrl.

has

Property
Type
Record<string, any> | undefined

Determines if the specified feature capabilities are supported.

map

Property
Type
Record<string, Record<string, string>> | undefined

Map paths in module identifiers to different paths.

packages

Property
Type
object[] | undefined

An array of objects which provide the package name and its location.

paths

Property
Type
Record<string, string> | undefined

Map of module id fragments to file paths.

RequestConfig

Type definition

httpsDomains

Property
Type
string[]

List of domain suffixes known to support https. This will automatically upgrade requests made to such domains to use https instead of http when the application is not running on http. Note that port numbers should not be included in the domain suffix to be matched.

If no httpsDomains list exists , the API redirects all calls using https. If the list exists and a domain of a required http resource is not listed, the API sends the URL as it is specified within the code. Likewise, if the list exists and the domain of a required http resource is listed in it, the API sends a https request to that resource.

The list includes the following domain suffixes by default:

  • arcgis.com
  • arcgisonline.com

interceptors

Property
Type
RequestInterceptor[]
Since
ArcGIS Maps SDK for JavaScript 4.8

Allows developers to modify requests before or after they are sent. The first interceptor that matches the request URL will be used.

Example:

const featureLayerUrl = "https://sampleserver6.arcgisonline.com/arcgis/rest/services/USA/MapServer/0";
config.request.interceptors.push({
// set the `urls` property to the URL of the FeatureLayer so that this
// interceptor only applies to requests made to the FeatureLayer URL
urls: featureLayerUrl,
// use the BeforeInterceptorCallback to check if the query of the
// FeatureLayer has a maxAllowableOffset property set.
// if so, then set the maxAllowableOffset to 0
before: (params) => {
if (params.requestOptions.query.maxAllowableOffset) {
params.requestOptions.query.maxAllowableOffset = 0;
}
},
// use the AfterInterceptorCallback to check if `ssl` is set to 'true'
// on the response to the request, if it's set to 'false', change
// the value to 'true' before returning the response
after: (response) => {
if (!response.ssl) {
response.ssl = true;
}
}
});

maxUrlLength

Property
Type
number

Maximum number of characters allowed in the URL for HTTP GET requests made by request. If this limit is exceeded, HTTP POST method will be used.

Default value
2000

priority

Property
Type
"auto" | "high" | "low"
Since
ArcGIS Maps SDK for JavaScript 4.24

The fetch and image network request priority. This is a hint to browsers on how important these requests are relative to other pending requests. The "auto" value lets browsers decide on the priority. They typically use "high" priority for fetch requests, and "low" priority for image requests. See more information at https://web.dev/priority-hints/. See browser support for this feature at https://caniuse.com/mdn-api_request_priority.

Default value
high

proxyRules

Property
Type
Array<RequestProxyRuleConfig>

A proxy rule defines a proxy for a set of resources with an identical URL prefix. When using esriRequest, if a target URL matches a rule, then the request will be sent to the specified proxy. Rather than populating this array directly, use the addProxyRule() method. Rule objects have the following properties:

proxyUrl

Property
Type
string | null | undefined

Resource proxy for your application. It is used by the library when communicating with a web server hosted on a domain that is different from the domain where your application is hosted.

The library may or may not use the proxy depending on the type of request made, whether the server support CORS, whether the application is being run on older versions of browsers etc.

const config = await $arcgis.import("@arcgis/core/config.js");
config.request.proxyUrl = "/proxy/Java/proxy.jsp";

timeout

Property
Type
number

Number of milliseconds request will wait for response from a server. If a server fails to respond before this time expires, then the request is considered to have encountered an error.

Default value
62000

trustedServers

Property
Type
string[]
Since
ArcGIS Maps SDK for JavaScript 4.9

Indicates whether cross-origin requests made to the associated server should include credentials such as cookies and authorization headers.

const config = await $arcgis.import("@arcgis/core/config.js");
config.request.trustedServers.push("[<protocol>//]<hostname>.<domain>[:<port>]");

useIdentity

Property
Type
boolean
Since
ArcGIS Maps SDK for JavaScript 4.5

Indicates whether esri/request will request a credential from IdentityManager.

Default value
true

SessionsConfig

Type definition
Since
ArcGIS Maps SDK for JavaScript 5.0

The configuration for sessions, which are used with an API key to manage user authentication and authorization with the API. The API key can be set using the apiKey property or the apiKeys.basemapStyles property.

Sessions are only used with API keys that are generated from an ArcGIS Location Platform account.

basemap

Property
Type
BasemapSessionConfig | undefined
Since
ArcGIS Maps SDK for JavaScript 5.0

Configuration for a basemap session for use with the basemap styles service.

BasemapSessionConfig

Type definition
Since
ArcGIS Maps SDK for JavaScript 5.0

Configuration for a basemap session for use with the basemap styles service. The basemap session is a timeframe during which a single user of a single application can use a session token to access unlimited basemap tiles from the Basemap Styles service.

When a basemap session is created, it provides a short-lived session token that can be used to access basemap styles and tiles from the basemap service for the duration of the session. The maximum duration a basemap session and session token are valid for is up to 12 hours.

Basemap sessions are only used with API keys that are generated from an ArcGIS Location Platform account.

enabled

Property
Type
boolean | undefined

Indicates whether the basemap session is enabled.

Default value
false

styleFamily

Property
Type
"arcgis" | "open" | undefined

The style family used by the basemap session.

A basemap session is valid only for a single style family. This setting determines which basemap styles and tiles can be accessed with the session token. If you switch to a basemap from a different style family, update this property. A new session (and session token) is created only if one does not already exist for the selected style family.

Default value
"arcgis"

autoRefresh

Property
Type
boolean | undefined

Indicates whether the basemap session should automatically refresh the session token when it expires.

Default value
false

duration

Property
Type
number | undefined

The duration of the basemap session in seconds. When the session expires, a new session token will need to be generated to access basemap styles and tiles from the basemap service. If autoRefresh is set to true, the session will automatically refresh the next time the session token is needed after the session expires.

If not provided, the session will default to 43200 seconds (12 hours). Valid range is from 10 to 43200 seconds.

Default value
43200

RequestProxyRuleConfig

Type definition

proxyUrl

Property
Type
string

The URL of the proxy.

urlPrefix

Property
Type
string

URL prefix for resources that need to be accessed through a specific proxy.

LogConfig

Type definition

interceptors

Property
Type
LogInterceptor[]

An array of custom interceptor functions that can be used to intercept log messages. Interceptors are invoked in order until an interceptor returns true. The default log handler that writes log messages to the console will be invoked last.

level

Property
Type
"none" | "error" | "warn" | "info" | null | undefined

The level of messages to log. All messages with severity higher or equal than the one configured will be logged. No messages will be logged if the specified level is "none". The default level if left undefined is "warn".