Skip to main content

Quick Start in Node.js

This document describes a basic integration using @globus/sdk in Node.js.

  • How to install the JavaScript SDK for Node.js.
  • How to write Node.js code to list files on a known Globus endpoint.
  • How to run the code.

Install the SDK

The @globus/sdk pacakge is distributed via npm  to get started, simply install the package.

npm install @globus/sdk
# or, using yarn:
# yarn install @globus/sdk

Credentials

caution

For brevity, this example assumes you have obtained a valid access token for use with Transfer's endpoint search. See Authorization in Node.js for more details on how to obtain a token for your application.

Writing a Simple ls Script

Create a new file named example.js to contain the sample code.

const { transfer } = require("@globus/sdk");

/**
* The ENDPOINT_ID provided here is a Globus Tutorial Endpoint, which is
* accessible to any authenticated Globus user. Feel free to change this
* value to any known, accessible, endpoint available to your account.
*/
const ENDPOINT_ID = "ddb59aef-6d04-11e5-ba46-22000b92c6ec";
const GLOBUS_AUTHORIZATION_TOKEN = process.env['GLOBUS_AUTHORIZATION_TOKEN'];

async function main() {
return await (
await transfer.ls(
ENDPOINT_ID,
{
query: {
path: "/~/",
},
headers: {
Authorization: "Bearer " + GLOBUS_AUTHORIZATION_TOKEN,
}
}
)
).json();
};

main();

Run the Example

node example.js

If the execution is successful, you should see a directory listing of your endpoint in your console.

Next Steps