# Azion Lib quickstart

This guide instructs you through your first Object Storage bucket created with [Azion Lib](/en/documentation/devtools/azion-lib/).

- Install the `@aziontech/storage` package.
- Set your personal token in the `AZION_TOKEN` environment variable.
- Create a bucket with a Node.js script.
- List the buckets of your account and read the response envelope.

The scripts work with two objects, in this order:

1. The **personal token** authorizes every call. The package reads it from `AZION_TOKEN` and sends it to Azion API v4.
2. The **bucket** is the [Object Storage](/en/documentation/platform/object-storage/) container that the first script creates. Every Storage function finds a bucket by its name.

---

## Prerequisites

- An Azion account. To create one, refer to [Create an account](/en/documentation/fundamentals/creating-account/).
- A personal token. To create one, refer to [Personal Tokens](/en/documentation/fundamentals/personal-tokens/).
- Node.js and npm. The scripts on this page are ES modules that use top-level `await`, and they run with the `node` command.

---

## Install the Storage package

The `@aziontech/storage` package holds the Azion Lib functions for Object Storage buckets and objects. In an empty directory for the project, install the package:

```bash
npm install @aziontech/storage
```

npm installs the package in the `node_modules` directory of the project, where the scripts import it from.

---

## Set your personal token

The Storage functions read your personal token from the `AZION_TOKEN` environment variable. In the terminal where you run the scripts, set the variable. Replace `[TOKEN VALUE]` with your token:

```bash
export AZION_TOKEN=[TOKEN VALUE]
```

Every script you start from this terminal reads the token, until the terminal closes. A client created with `createClient` takes the token in its `token` field instead. For more information, refer to [Storage](/en/documentation/devtools/azion-lib/storage/#createclient).

---

## Create a bucket

The `createBucket` function creates a bucket from a `name` and a `workloads_access` access level. A bucket name is unique across every Azion account, so replace `my-bucket` in the script with a name of your own. For the naming rules and the access levels, refer to [Buckets and objects](/en/documentation/platform/object-storage/buckets-and-objects/).

Create a file named `create-bucket.mjs` with the following code:

```javascript
import { createBucket } from '@aziontech/storage';

const { data, error } = await createBucket({
  name: 'my-bucket',
  workloads_access: 'read_only',
});
if (data) {
  console.log(`Bucket created with name: ${data.name}`);
} else {
  console.error('Failed to create bucket', error);
}
```

Run the script:

```bash
node create-bucket.mjs
```

The script prints the name of the bucket it created:

```text
Bucket created with name: my-bucket
```

Your account has a bucket named `my-bucket`, with the `read_only` access level.

---

## List the buckets and read the response envelope

Every Storage function returns a response envelope, `{ data, error }`, instead of throwing an error. On success, `data` holds the result. On failure, `data` is absent and `error` holds two fields: `message`, the reason, and `operation`, the call that failed.

The `getBuckets` function lists the buckets of your account, one page at a time. Create a file named `list-buckets.mjs` with the following code:

```javascript
import { getBuckets } from '@aziontech/storage';

const { data: buckets, error } = await getBuckets({
  params: { page: 1, page_size: 10 },
});
if (buckets) {
  console.log(`Retrieved ${buckets.buckets.length} of ${buckets.count} buckets`);
} else {
  console.error('Failed to retrieve buckets', error);
}
```

Run the script:

```bash
node list-buckets.mjs
```

The script prints the length of the page and the number of buckets in the account. The page holds at most the 10 buckets that `page_size` sets:

```text
Retrieved 10 of 25 buckets
```

In `data`, `buckets` holds the page of buckets, and `count` holds the number of buckets in the account, not the length of the page. If the terminal has no `AZION_TOKEN`, the call returns `error` instead: `message` reads `Authentication credentials were not provided.` and `operation` reads `get all buckets`.

The `count` includes the bucket that `create-bucket.mjs` created. For every error message the Storage functions return, refer to [Storage](/en/documentation/devtools/azion-lib/storage/#errors).

---

## Next steps

- [Storage](/en/documentation/devtools/azion-lib/storage.md): Every bucket and object function of @aziontech/storage, with its parameters and errors.
- [How Azion Lib works](/en/documentation/devtools/azion-lib/how-it-works.md): The packages, how each module finds your token, and the debug setting.
- [SQL](/en/documentation/devtools/azion-lib/sql.md): Create SQL databases and run queries with the @aziontech/sql package.
- [Object Storage](/en/documentation/platform/object-storage.md): What a bucket stores, its access levels, and how an application serves it.
