Create a code bundle

Refer to these guidelines when creating your EdgeKV-enabled EdgeWorkers code bundle.

To create a code bundle, package the following files together, along with any other dependencies as a compressed .tgz (tarball) file:

  • main.js

  • bundle.json

  • edgekv.js (helper library)

  • edgekv_tokens.js (access token)

    For more information go to Create a code bundle in the EdgeWorkers User Guide.

Add the main.js and bundle.json files

The main.js file contains JavaScript source code that contains the event handler functions for EdgeWorkers. The bundle.json file is the manifest file that includes the necessary metadata information about your application.

  1. Create a local folder for your EdgeWorkers code bundle.

  2. Create the main.js file, write your EdgeWorkers code, and add it to the code bundle folder.

    You need to use the following import statement to add the edgekv.js helper file to your code bundle:

import { EdgeKV } from './edgekv.js';

📘

You'll receive an error message if this import statement is missing even if the edgekv.js helper file is included in the code bundle.

👍

You can also download the hello-world example from the EdgeKV GitHub repo.

  1. Create the bundle.json manifest file and add it to the code bundle folder.

    For instructions on how to create a bundle.json file see Create a code bundle in the EdgeWorkers User Guide.

Add the EdgeKV helper library

Make sure you include the JavaScript helper library that you downloaded in the code bundle. It is required to access the EdgeKV database.

  1. Copy the edgekv.js file to your code bundle folder.

📘

The the edgekv.js helper file is not required when using the administrative APIs to control EdgeKV database functions outside of EdgeWorkers code.

Add the access token file

The edgekv.js library automatically uses the appropriate token to access the corresponding namespace. If a token is missing, an exception is thrown by the EdgeKV methods with a 401 error.

  1. Add the edgekv_tokens.js file containing the EdgeKV access token to your EdgeWorkers code bundle folder.