# Manage folders and labels with Node.js

Source: https://developer.nylas.com/docs/v3/sdks/node/manage-folders-labels/

This page explains how to use the Nylas Node.js SDK and Email API to organize a user's inbox using folders and labels.

## Before you begin

Before you start, you must have done the following tasks:

- [Installed and set up the Nylas Node.js SDK](/docs/v3/sdks/node/).
- [Authenticated one or more users](/docs/v3/sdks/node/#authenticate-users).

## List folders and labels

Depending on the user's email provider, there are two possible ways their inbox might be organized: using either folders or labels. Gmail uses labels, and all other providers use folders. Nylas consolidates both folders and labels under the [Folders endpoint](/docs/reference/api/folders/).

The following example lists all folders and labels from a user's inbox.

```js
async function fetchFolders() {
  try {
    const folders = await nylas.folders.list({
      identifier: "<NYLAS_GRANT_ID>",
    });

    console.log("folders:", folders);
  } catch (error) {
    console.error("Error fetching folders:", error);
  }
}

fetchFolders();
```

## Create folders and labels

The following example creates a folder called "Cat Pics!" and applies it to the most recent message in the user's inbox.

```js


const NylasConfig = {
  apiKey: "<NYLAS_API_KEY>",
  apiUri: "<NYLAS_API_URI>",
};

const nylas = new Nylas(NylasConfig);
const identifier = "<NYLAS_GRANT_ID>";
const messageId = "<MESSAGE_ID>";
let folderId = "";

const createFolder = async () => {
  try {
    const folder = await nylas.folders.create({
      identifier,
      requestBody: {
        name: "Cat Pics!",
      },
    });

    console.log("Folder created:", folder);
    folderId = folder.data.id;
  } catch (error) {
    console.error("Error creating folder:", error);
  }
};

const updateMessageFolder = async () => {
  try {
    const updatedMessage = await nylas.messages.update({
      identifier,
      messageId,
      requestBody: {
        folders: [folderId],
      },
    });

    console.log("Message updated:", updatedMessage);
  } catch (error) {
    console.error("Error updating message folder:", error);
  }
};

await createFolder();
await updateMessageFolder();
```