# Node.js

N'importe quel backend Node.js 18+ fonctionne : Express, Fastify, NestJS, Hono ou simplement `http`. Node 18+ intègre nativement `fetch`, `FormData` et `Blob` ; aucune bibliothèque HTTP n'est donc nécessaire.

## Express

```js
import express from "express"
import multer from "multer"

const app = express()
const upload = multer({ limits: { fileSize: 15 * 1024 * 1024 } })

app.post("/try-on", upload.single("person"), async (req, res) => {
  const form = new FormData()
  form.append("person_image", new Blob([req.file.buffer]), "person.jpg")
  form.append("garment_url", req.body.garmentUrl)

  const r = await fetch("https://www.tryoncloud.com/api/v1/generate", {
    method: "POST",
    headers: { "X-API-KEY": process.env.TRYONCLOUD_API_KEY },
    body: form,
    signal: AbortSignal.timeout(120_000),
  })
  if (!r.ok) return res.status(r.status).json(await r.json())
  res.type("png").send(Buffer.from(await r.arrayBuffer()))
})

app.listen(3000)
```

## Avec le SDK

```js
import { TryOnCloud } from "./tryoncloud.mjs"

const client = new TryOnCloud()
const { image } = await client.generate({
  garment: { url: "https://cdn.yourstore.com/shirt.jpg" },
  person: { data: personBuffer },
})
```

Consultez les sections « [TypeScript SDK](/docs/sdk)» et [Erreurs](/docs/errors) pour en savoir plus sur la gestion des nouvelles tentatives.
