---
title: "DWS Processor API with JavaScript and TypeScript"
canonical_url: "https://www.nutrient.io/guides/dws-processor/supported-languages/javascript/"
md_url: "https://www.nutrient.io/guides/dws-processor/supported-languages/javascript.md"
last_updated: "2026-05-27T15:15:53.462Z"
description: "Learn how to use Nutrient DWS Processor API with JavaScript and TypeScript to process documents through HTTP requests and enhance your development experience."
---

With Nutrient DWS Processor API, you can process your documents by making HTTP requests to one of our [50+ API tools](https://dashboard.nutrient.io/processor-api/playground/). You can make a single request to one tool or combine API actions to generate, edit, OCR, and convert your document (1 document can have multiple API actions).

This guide applies to both JavaScript and TypeScript. Our official client library is written in TypeScript and ships with full type definitions.

## Using our TypeScript/JavaScript client

For the best developer experience, we recommend using our [official TypeScript/JavaScript client library](https://github.com/PSPDFKit-labs/nutrient-dws-client-typescript).

### Installation

```sh

npm install @nutrient-sdk/dws-client-typescript

# Enable enhanced code completion and documentation for Claude Code using the Nutrient DWS SDK.

npx dws-add-claude-code-rule

# Enable enhanced code completion and documentation for GitHub Copilot using the Nutrient DWS SDK.

npx dws-add-github-copilot-rule

# Enable enhanced code completion and documentation for Junie (Jetbrains) using the Nutrient DWS SDK.

npx dws-add-junie-rule

# Enable enhanced code completion and documentation for Cursor using the Nutrient DWS SDK.

npx dws-add-cursor-rule

# Enable enhanced code completion and documentation for Windsurf using the Nutrient DWS SDK.

npx dws-add-windsurf-rule

```

### Example

```js

import { NutrientClient } from '@nutrient-sdk/dws-client-typescript';
import fs from 'fs';

const client = new NutrientClient({
  apiKey: 'your_api_key_here',
});

// Add an image watermark to a document.
const imageResult = await client.watermarkImage('./document.pdf', './logo.png', {
  width: { value: 50, unit: '%' }
});

fs.writeFileSync('./watermarked-document.pdf', Buffer.from(imageResult.buffer));

// Redact and archive a document set using a chained workflow.
const archivedResult = await client.workflow()
  // Add documents from multiple formats (PDF, DOCX, PNG)..addFilePart("./form.docx").addFilePart("./policy.pdf").addFilePart("./image.png")
  // Apply multiple actions: watermark and redactions using `applyActions`..applyActions([
    BuildActions.createRedactionsPreset('email-address'),
    BuildActions.createRedactionsPreset('international-phone-number'),
    BuildActions.createRedactionsPreset('north-american-phone-number'),
    BuildActions.applyRedactions(),
    BuildActions.watermarkText('ARCHIVED', {
      opacity: 0.45,
      fontSize: 32,
      fontColor: '#FF0000',

      rotation: 45,
      fontStyle: ['bold']
    }),
  ])
  // Output as PDF/A format..outputPdfA({
    conformance: 'pdfa-2b',
    vectorization: true,
    metadata: {
      title: 'Multi-Format Merged Document',
      author: 'Archive.org',
    },
    optimize: {
      mrcCompression: true,
      imageOptimizationQuality: 3
    }
  })
  // Tracking progress..execute({
    onProgress: (current: number, total: number) => {
      console.log(`Processing step ${current} of ${total}`);
    }
  });

fs.writeFileSync('./archived-document.pdf', Buffer.from(archivedResult.buffer));

```

## Alternative: Using raw HTTP requests

If you prefer to use raw HTTP requests or want to understand the underlying API calls, you can also interact with the API directly using any HTTP client.

Nutrient DWS Processor API is designed to be used from a server and not a browser, so this section demonstrates how to use [Node.js](https://nodejs.org/en/) and the [axios HTTP library](https://axios-http.com) to make HTTP requests with Nutrient DWS Processor API. Keep in mind that you can use any HTTP client you want; this example uses axios to demonstrate the principles of interacting with Nutrient DWS Processor API.

It involves three main steps:

1. Installing the required dependencies

2. Preparing the payload

3. Making the request

#### Installing the required dependencies

The first thing you need to do is create a new Node.js app and install the dependencies.

For the `npm init` call, press return for all of the questions to accept their defaults:

```sh

npm init
npm install axios
npm install form-data

```

You’ll also need to add `document.pdf` and `logo.png` files to the root of your Node.js project (the same folder you’ll be creating the `index.js` file in). You can use the sample files provided by us — [document.pdf](https://www.nutrient.io/assets/guides/dws-processor/watermark/document.pdf) and [logo.png](https://www.nutrient.io/assets/guides/dws-processor/watermark/logo.png) — or use your own.

Now that you have your dependencies and assets set up, you’re ready to start making requests to Nutrient DWS Processor API.

First, create an `index.js` file, which will contain your code to call Nutrient DWS Processor API. You can immediately import your dependencies as well:

```js

const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");

```

Next, you’ll prepare the payload.

#### Preparing the payload

You can create your `FormData` object, which contains the instructions and all the files sent to the API. You’ll start with the `instructions` object:

```js

const formData = new FormData();
formData.append(
  "instructions",
  JSON.stringify({
    parts: [
      {
        file: "document",
      },
    ],
    actions: [
      {
        type: "watermark",
        image: "company-logo",
        width: "50%",
      },
      {
        type: "watermark",
        text: "Property of Nutrient",
        width: 150,
        height: 20,
        left: 0,
        bottom: "100%",
      },
    ],
  }),
);

```

Here, you add your `instructions` JSON to your `FormData` object. In this example, you’ll be adding an image watermark. For examples of how the watermark API can be used (for example, adding multiple watermarks to the document, watermarking the last page of the document, and watermark alignments), refer to our [PDF watermark API](https://www.nutrient.io/api/pdf-watermark-api/) page.

Next, you need to include your source assets, `document.pdf` and `logo.png`, with your request:

```js

formData.append("document", fs.createReadStream("document.pdf"));
formData.append("company-logo", fs.createReadStream("logo.png"));

```

Now, you’ll make the request.

#### Making the request

With your `FormData` object being populated, you can now send the actual request. Make sure to replace the `your_api_key_here` placeholder with your actual API key if it hasn’t yet been replaced:

```js

axios.post("https://api.nutrient.io/build", formData, {
    headers: formData.getHeaders({
      Authorization: "Bearer your_api_key_here",
    }),
    responseType: "stream",
  }).then(function (response) {
    response.data.pipe(fs.createWriteStream("result.pdf"));
  }).catch(async function (e) {
    console.log(e);
    const errorString = await streamToString(e.response.data);
    console.log(errorString);
  });

function streamToString(stream) {
  const chunks = [];
  return new Promise((resolve, reject) => {
    stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
    stream.on("error", (err) => reject(err));
    stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
  });
}

```

Here, you’re setting the `responseType` to `stream` to make sure the resulting PDF isn’t loaded entirely into memory. You also write the final result to `result.pdf`. And with that, you’re done. You can now run your code using `node index.js`, and `result.pdf` should be created.

While this example made use of our watermarking API, this same approach can be used for all our available [API tools](https://dashboard.nutrient.io/processor-api/playground/).

> `streamToString` only exists to format any errors you might receive, as you can’t print the stream directly.

## Complete code

For your convenience, the complete code is below:

```js

const axios = require("axios");
const FormData = require("form-data");
const fs = require("fs");

const formData = new FormData();
formData.append(
  "instructions",
  JSON.stringify({
    parts: [
      {
        file: "document",
      },
    ],
    actions: [
      {
        type: "watermark",
        image: "company-logo",
        width: "50%",
      },
      {
        type: "watermark",
        text: "Property of Nutrient",
        width: 150,
        height: 20,
        left: 0,
        bottom: "100%",
      },
    ],
  }),
);

formData.append("document", fs.createReadStream("document.pdf"));
formData.append("company-logo", fs.createReadStream("logo.png"));

axios.post("https://api.nutrient.io/build", formData, {
    headers: formData.getHeaders({
      Authorization: "Bearer your_api_key_here",
    }),
    responseType: "stream",
  }).then(function (response) {
    response.data.pipe(fs.createWriteStream("result.pdf"));
  }).catch(async function (e) {
    console.log(e);
    const errorString = await streamToString(e.response.data);
    console.log(errorString);
  });

function streamToString(stream) {
  const chunks = [];
  return new Promise((resolve, reject) => {
    stream.on("data", (chunk) => chunks.push(Buffer.from(chunk)));
    stream.on("error", (err) => reject(err));
    stream.on("end", () => resolve(Buffer.concat(chunks).toString("utf8")));
  });
}

```
---

## Related pages

- [Supported languages](/guides/dws-processor/supported-languages.md)
- [DWS Processor API with Java](/guides/dws-processor/supported-languages/java.md)
- [DWS Processor API with C#](/guides/dws-processor/supported-languages/csharp.md)
- [DWS Processor API with PHP](/guides/dws-processor/supported-languages/php.md)
- [DWS Processor API with other languages](/guides/dws-processor/supported-languages/other.md)
- [Enable enhanced code completion and documentation for Claude Code using the Nutrient DWS SDK.](/guides/dws-processor/supported-languages/python.md)

