> ## Documentation Index
> Fetch the complete documentation index at: https://docs.docex.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Express

> Add a file upload endpoint to an Express app that routes through Docex for vision analysis.

# Express

> Add a file upload endpoint to an Express app that routes through Docex for vision analysis.

## Prerequisites

* Express 4+
* `docexdev` installed
* `multer` or similar for file upload handling
* `DOCEX_API_KEY` and `DOCEX_BASE_URL` configured

## Server

```js theme={null}
import express from "express";
import multer from "multer";
import { createDocex } from "docexdev";

const app = express();
const upload = multer({ storage: multer.memoryStorage() });

const docex = createDocex({
  apiKey: process.env.DOCEX_API_KEY,
  baseUrl: process.env.DOCEX_BASE_URL,
});

app.post("/api/analyze", upload.single("file"), async (req, res) => {
  try {
    const result = await docex.run({
      file: { fileName: req.file.originalname, data: req.file.buffer },
      prompt: req.body.prompt,
    });

    res.json(result);
  } catch (err) {
    res.status(err.status || 500).json({
      error: err.code,
      message: err.message,
      suggestion: err.suggestion,
    });
  }
});

app.listen(3000, () => console.log("Server running on http://localhost:3000"));
```

## Test

```bash theme={null}
curl -X POST http://localhost:3000/api/analyze \
  -F "file=@invoice.pdf" \
  -F "prompt=Extract line items, totals, and vendor details"
```

## Environment variables

```bash theme={null}
DOCEX_API_KEY=dx_live_...
DOCEX_BASE_URL=https://api.docex.dev
```

<Warning>
  Keep `DOCEX_API_KEY` server-side only. Do not send it to the client.
</Warning>
