Node.js + PixelPanda API
Remove Background with Node.js
Remove image backgrounds from your Node.js backend. Complete examples for Express, Next.js, and serverless functions.
Install
Code examples
Node.js examples — copy and go
Each example is self-contained. Copy the one that matches your use case.
Quick start
Basic background removal from a Node.js script.
const fs = require("fs");
const FormData = require("form-data");
const API_KEY = "pk_live_your_api_key";
async function removeBackground(imagePath) {
const form = new FormData();
form.append("file", fs.createReadStream(imagePath));
const response = await fetch(
"https://pixelpanda.ai/api/v1/remove-background",
{
method: "POST",
headers: {
"Authorization": `Bearer ${API_KEY}`,
...form.getHeaders()
},
body: form
}
);
return await response.json();
}
const result = await removeBackground("product.jpg");
console.log(result.image_url); // Transparent PNG URLExpress middleware
Add background removal to your Express API.
const express = require("express");
const multer = require("multer");
const FormData = require("form-data");
const app = express();
const upload = multer({ limits: { fileSize: 10 * 1024 * 1024 } });
app.post("/api/remove-bg", upload.single("image"), async (req, res) => {
if (!req.file) return res.status(400).json({ error: "No image" });
const form = new FormData();
form.append("file", req.file.buffer, {
filename: req.file.originalname,
contentType: req.file.mimetype
});
try {
const response = await fetch(
"https://pixelpanda.ai/api/v1/remove-background",
{
method: "POST",
headers: {
"Authorization": `Bearer ${process.env.PIXELPANDA_API_KEY}`,
...form.getHeaders()
},
body: form
}
);
const data = await response.json();
res.json(data);
} catch (err) {
res.status(500).json({ error: err.message });
}
});
app.listen(3000);API reference
Response format
Every successful request returns this JSON. The image_url is a permanent link to the transparent PNG.
{
"success": true,
"image_url": "https://pub-xxx.r2.dev/results/abc123.png",
"credits_remaining": 199
}| Field | Type | Description |
|---|---|---|
| success | boolean | true if background was removed successfully |
| image_url | string | URL to the transparent PNG result (permanent, hosted on CDN) |
| credits_remaining | integer | How many credits are left on your account |
Error codes
| Code | Meaning |
|---|---|
| 200 | Success — image_url contains the transparent PNG |
| 401 | Unauthorized — invalid or missing API key |
| 402 | Payment required — out of credits |
| 429 | Rate limited — too many requests |
Troubleshooting
Common issues
form.getHeaders is not a function
Make sure you're using the form-data npm package, not the browser's built-in FormData. Install it: npm install form-data.
fetch is not defined
Node.js 18+ has built-in fetch. For older versions, install node-fetch: npm install node-fetch.
FAQ
Common questions
Yes. See the JavaScript page for a Next.js API route example. Works with both Pages Router and App Router.
Yes. The API is a stateless HTTP POST — perfect for AWS Lambda, Vercel Functions, or Cloudflare Workers.
Node.js 18+ has built-in fetch(). For older versions, npm install node-fetch.
1 credit per image (~$0.029). Start with the $10 Impulse pack (50 credits, one-time, no subscription) or subscribe at $7.99/week for 280 credits/week (cancel anytime).
More languages
By platform
Start removing backgrounds with Node.js
280 credits/week for $7.99. Copy the code above and go.
Get Your API Key