Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

akamai-edgegrid

akamai-open188.9kApache-2.04.0.0TypeScript support: included

Authentication handler for the Akamai OPEN EdgeGrid Authentication scheme in Node.js

akamai, open, api, edgegrid

readme

EdgeGrid for Node.js

Build Status

This library implements an Authentication handler for the Akamai EdgeGrid Authentication scheme in Node.js for Node v20 and higher LTS versions.

You can find the most up-to-date package in NPM under akamai-edgegrid.

Install

npm install --save akamai-edgegrid

Authentication

You can obtain the authentication credentials through an API client. Requests to the API are marked with a timestamp and a signature and are executed immediately.

  1. Create authentication credentials.

  2. Place your credentials in an EdgeGrid file ~/.edgerc, in the [default] section.

     [default]
     client_secret = C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=
     host = akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net
     access_token = akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij
     client_token = akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj
  3. Use your local .edgerc by providing the path to your resource file and credentials' section header.

     var eg = new EdgeGrid({
       path: '/path/to/.edgerc',
       section: '<section-header>'
     });

    Alternatively, you can hard code your credentials by passing the credential values to the EdgeGrid() method.

     var clientToken = "akab-c113ntt0k3n4qtari252bfxxbsl-yvsdj",
         clientSecret = "C113nt53KR3TN6N90yVuAgICxIRwsObLi0E67/N8eRN=",
         accessToken = "akab-acc35t0k3nodujqunph3w7hzp7-gtm6ij",
         baseUri = "akab-h05tnam3wl42son7nktnlnnx-kbob3i3v.luna.akamaiapis.net";
    
     var eg = new EdgeGrid(clientToken, clientSecret, accessToken, baseUri);

Use

To use the library, provide the path to your .edgerc, your credentials section header, and the appropriate endpoint information.

var EdgeGrid = require('akamai-edgegrid');

var eg = new EdgeGrid({
  path: '/path/to/.edgerc',
  section: 'section-header'
});

eg.auth({
  path: '/identity-management/v3/user-profile',
  method: 'GET',
  headers: {
    'Accept': "application/json"
  },
  body: {}
});

eg.send(function(error, response, body) {
  console.log(body);
});

Chaining

You can also chain calls by combining the execution of auth and send methods.

eg.auth({
  path: '/identity-management/v3/user-profile',
  method: 'GET',
  headers: {},
  body: {}
}).send(function (error, response, body) {
  console.log(body);
});

Query string parameters

When entering query parameters use the qs property under the auth method. Set up the parameters as name-value pairs in a object.

eg.auth({
    path: '/identity-management/v3/user-profile',
    method: 'GET',
    headers: {},
    qs: {
        authGrants: true,
        notifications: true,
        actions: true
    },
    body: {}
})

Headers

Enter request headers as name-value pairs in an object.

Note: You don't need to include the Content-Type and Content-Length headers. The authentication layer adds these values.

eg.auth({
  path: '/identity-management/v3/user-profile',
  method: 'GET',
  headers: {
    'Accept': "application/json"
  }
});

Body data

Provide the request body as an object or as a POST data formatted string.

// Object
eg.auth({
    path: '/identity-management/v3/user-profile/basic-info',
    method: 'PUT',
    headers: {},
    body: {
        contactType: "Billing",
        country: "USA",
        firstName: "John",
        lastName: "Smith",
        phone: "3456788765",
        preferredLanguage: "English",
        sessionTimeOut: 30,
        timeZone: "GMT"
   }
});

Encoding

When interacting with binary data, such as during the retrieval of PDF invoices, specify the responseType as an arraybuffer in the auth method call. Omitting the responseType will cause an unreadable or blank response.

const fs = require('fs');

eg.auth({
  path : `/invoicing-api/v2/contracts/${contractId}/invoices/${invoiceNumber}/files/${fileName}`,
  method: 'GET',
  responseType: 'arraybuffer', // Important
}).send((err, response) => {
  if (err) {
    return console.log(err);
  }
  fs.writeFile(`./${fileName}`, response.data, 'binary', (err) => {
    if (err){
      return console.log(err);
    }
    console.log('File was saved!');
  });
});

Logging

The library supports configurable logging through the enableLogging() method.

  • enableLogging()

    • Enable with Environment Variables:

      • AKAMAI_LOG_LEVEL (Default: 'info')

        • Valid values:
          • 'error'
          • 'warn'
          • 'info'
          • 'debug'
          • 'fatal'
          • 'trace'
      • AKAMAI_LOG_PRETTY (Default: 'false')

        • Valid values: 'true' or 'false'
const edgeGrid = require('akamai-edgegrid');

// Set environment variables before enabling
process.env.AKAMAI_LOG_LEVEL = 'debug';
process.env.AKAMAI_LOG_PRETTY = 'true';

var eg = new EdgeGrid({
    path: '/path/to/.edgerc', 
    section: '<section-header>'
});
eg.enableLogging(true);
  • Disable Logging:

    const edgeGrid = require('akamai-edgegrid');
    var eg = new EdgeGrid({
    path: '/path/to/.edgerc',
    section: '<section-header>'
    });
    eg.enableLogging(false);
  • Custom Logger:

    • You can also pass a custom logger object to enableLogging. The object must have info, debug, error and warn methods.
    • If you pass an object that does not implement the required info, debug, error and warn methods, an error will be thrown.
const edgeGrid = require('akamai-edgegrid');
//custom logger
const logger = {
  info: (msg, ...args) => console.log('INFO:', msg, ...args),
  debug: (msg, ...args) => console.log('DEBUG:', msg, ...args),
  error: (msg, ...args) => console.error('ERROR:', msg, ...args),
  warn: (msg, ...args) => console.warn('WARN:', msg, ...args)  
};

var eg = new EdgeGrid({
    path: '/path/to/.edgerc',
    section: '<section-header>'
});

eg.enableLogging(logger); // Pass the custom logger 

logger.info('Using custom logger for logging.');
logger.error('An error occurred!');

Proxy

To use edgegrid with proxy, you can configure it with one of these methods:

  • Add the proxy argument to the EdgeGrid() method.

    eg.auth({
      path : `/identity-management/v3/user-profile`,
      method: 'GET',
      proxy: {
        host: 'my.proxy.com',
        protocol: "https",
        port: 3128,
        auth: {
          username: 'my-user',
          password: 'my-password'
        }
      }
    }).send((err, response) => {
      if (err) {
        return console.log(err);
      }
      console.log('Success!');
      // Do something with the response
    });
  • Set the HTTPS_PROXY environment variable.

    $ export HTTPS_PROXY=https://username:password@host:port
    $ node myapp.js

Reporting issues

To report an issue or make a suggestion, create a new GitHub issue.

License

Copyright 2025 Akamai Technologies, Inc. All rights reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use these files except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0.

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

changelog

Release notes

4.0.0 (Dec 4, 2025)

Breaking Changes

  • Replaced log4js with pino for logging and removed the log4js dependency.
  • Updated logging configuration with the following environment variables:
    • AKAMAI_LOG_LEVEL - controls log severity. Possible values are: fatal, error, warn, info, debug, or trace. Defaults to info.
    • AKAMAI_LOG_PRETTY - enables pretty-printed, human-readable log format when set to true. Defaults to false.
  • Logging is now disabled by default, ensuring zero logging unless explicitly enabled.
  • Introduced the enableLogging(option) function to programmatically control logging:
    • Passing true enables logging based on environment variables.
    • Passing a valid "pino-like" logger object sets the current logger. Custom loggers must implement the info, debug, error, and warn methods.
  • Exported enableLogging for external use, replacing the previous default logger export.
  • Removed support for the EG_VERBOSE environment variable; Axios interceptors now always log at the debug level.
  • Removed support for the debug parameter from the EdgeGrid constructor; debugging is now fully managed through enableLogging().

Features/Enhancements

  • Updated various dependencies.

3.5.6 (Oct 15, 2025)

Bug fixes

  • Replaced uuid package with crypto after uuid v13 dropped CommonJS support, to fix the compatibility issues.

3.5.5 (Oct 8, 2025)

Features/Enhancements

  • Updated various dependencies.
  • Removed support for Node.js versions 18, 21, and 23.

3.5.4 (Jul 24, 2025)

Features/Enhancements

  • Updated various dependencies.
  • Removed support for Node.js versions 14 and 16.

3.5.3 (Apr 09, 2025)

Features/Enhancements

  • Updated various dependencies.

3.5.2 (Dec 05, 2024)

Features/Enhancements

  • Updated various dependencies.

3.5.1 (Sep 10, 2024)

Features/Enhancements

  • Updated various dependencies.

3.5.0 (Jul 02, 2024)

Features/Enhancements

  • Updated various dependencies.

Bug fixes

  • max_body is deprecated, ignored and replaced with a constant value of 131072 bytes.

3.4.5 (Apr 3, 2024)

Bug fixes

  • Fixed a bug where the max_body parameter was not utilized when generating the authentication header.
  • Implemented support for the max_body parameter when the configuration is provided as a function parameter.

Features/Enhancements

  • Updated various dependencies.

3.4.4 (Nov 15, 2023)

Features/Enhancements

  • Updated various dependencies.

3.4.3 (Oct 23, 2023)

Features/Enhancements

  • Updated various dependencies.

3.4.2 (Sep 12, 2023)

Bug fixes

  • Don't set the default '' (empty) body in the requests.

Features/Enhancements

  • Updated various dependencies.

3.4.1 (May 09, 2023)

Features/Enhancements

  • Updated various dependencies.

3.4.0 (Jan 26, 2023)

Features/Enhancements

  • Added reading of the max_body (alias max-body) field from .edgerc config file with a default value of 131072 (PR#1).
  • Added a default Accept header (related to PR#43 and I#33).
  • Added the README section explaining how to use proxy (related to PR#35 and I#59).
  • Added the README section explaining how to change request encoding (related to PR#58).
  • Updated various dependencies.

3.3.0 (Nov 08, 2022)

Features/Enhancements

  • Updated various dependencies.

Bug fixes

  • Fixed adding the User-Agent header to the request.

3.2.0 (Apr 26, 2022)

Features/Enhancements

  • Added the Typescript declaration file (#71).

3.1.4 (Mar 24, 2022)

Features/Enhancements

  • Removed a deprecated moment dependency.

Bug fixes

  • Fixed the response when Content-Type is application/gzip (#83).

3.1.3 (Feb 22, 2022)

Features/Enhancements

  • Updated various dependencies.

Bug fixes

3.1.2 (Nov 3, 2021)

Notes

  • [IMPORTANT] Changed the npm package name from edgegrid to akamai-edgegrid.
  • Cleaned up README.md to include working examples and got rid of inconsistencies.

3.1.1 (Sep 28, 2021)

Bug fixes

  • Updated the version of axios to 0.21.4 to get rid of the ReDoS vulnerability.

3.1.0 (Sep 27, 2021)

Bug fixes

  • Fixed support of environment variables (#27).
  • Fixed an error when Tarball exceeds a max-body size (#33).

Features/Enhancements

  • Replaced the request package with axios (#64).
  • Fixed code quality issues.
  • Updated the version of mocha.
  • Added a resolving ~ sign in the edgerc path.