Module Usage

If you are developing your own JavaScript application using a NodeJS server or using NPM libraries, you can use our NPM module instead which offers greater flexibility than using the standard combined library.

Once you have an active Aeris API account and access keys for your application, follow these steps to get started using the NPM module:

Step 1: Install the latest version of the SDK module:

yarn add @aerisweather/javascript-sdk

Alternatively, if you’re using NPM:

npm install @aerisweather/javascript-sdk

Step 2: Import the module into your project:

import aeris from '@aerisweather/javascript-sdk';

Step 3: Set your account access keys when the page and scripts have loaded:

const aeris = new AerisWeather('CLIENT_KEY', 'CLIENT_SECRET');

Step 4: Start using the library by accessing the available convenience methods on your AerisWeather instance:

aeris.api().endpoint('observations').place('seattle,wa').get().then((result) => {
     var data = result.data.ob;
     console.log(`The current weather is ${data.weatherPrimary.toLowerCase()} and ${data.tempF} degrees.`);
});

Review the Loading Data guide for information on getting data into your application now that you have everything set up.

Using Individual Classes

One benefit to using the SDK as an NPM module is that you have access to the entire set of classes throughout the SDK and aren’t limited to functionality exposed by the core AerisWeather object.

For instance, you can opt to not use the AerisWeather class altogether and create request instances directly using imports from the SDK’s module. The following is an example of creating an ApiRequest instance directly instead of using AerisWeather.api():

import ApiRequest from '@aerisweather/javascript-sdk/dist/network/api/ApiRequest';

const request = new ApiRequest({
     client: {
          id: 'CLIENT_ID',
          secret: 'CLIENT_SECRET'
     }
});

// configure and perform the request 
request.endpoint('forecasts').place('minneapolis,mn').get().then((result) => {
     console.log(result.data);
});

You can use the same approach by importing MapRequest directly as well to retrieve AMP imagery:

import MapRequest from '@aerisweather/javascript-sdk/dist/network/maps/MapRequest';

const request = new MapRequest({
     client: {
          id: 'CLIENT_ID',
          secret: 'CLIENT_SECRET'
     }
});

// configure and perform the request
request.layers('flat,radar,admin').center('minneapolis,mn').zoom(8).size(500, 300).get().then((result) => {
    console.log(result.image, result.metadata);
});

Review our complete developer SDK documentation for the additional information about the classes and their roles used throughout the SDK.