Quick Start
Get started with the Easy Node.js SDK in minutes.
Basic Setup
import { createClient } from "@easylabs/node";
// Initialize the client
const easy = await createClient({
apiKey: "your-api-key",
});
// Use the client
const customers = await easy.getCustomers();
console.log(customers);
Express.js Integration
import express from "express";
import { createClient } from "@easylabs/node";
const app = express();
app.use(express.json());
// Initialize Easy client
const easy = await createClient({
apiKey: process.env.EASY_API_KEY,
});
app.post("/api/customers", async (req, res) => {
try {
const customer = await easy.createCustomer({
first_name: req.body.firstName,
last_name: req.body.lastName,
email: req.body.email,
});
res.json(customer);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.listen(3000);
Next.js API Route
// pages/api/customers/[id].ts
import { createClient } from "@easylabs/node";
import type { NextApiRequest, NextApiResponse } from "next";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse,
) {
const easy = await createClient({
apiKey: process.env.EASY_API_KEY!,
});
const customerId = req.query.id as string;
if (req.method === "GET") {
const customer = await easy.getCustomer(customerId);
res.json(customer);
} else if (req.method === "PATCH") {
const updated = await easy.updateCustomer(customerId, req.body);
res.json(updated);
} else {
res.status(405).end();
}
}
Environment Configuration
Create a .env file in your project root:
EASY_API_KEY=your_secret_api_key_here
NODE_ENV=development
Then use it in your application:
import { createClient } from "@easylabs/node";
import dotenv from "dotenv";
dotenv.config();
const easy = await createClient({
apiKey: process.env.EASY_API_KEY!,
__dev: process.env.NODE_ENV === "development",
});
Simple Payment Example
import { createClient } from "@easylabs/node";
const easy = await createClient({
apiKey: process.env.EASY_API_KEY!,
});
// Create a customer
const customer = await easy.createCustomer({
first_name: "John",
last_name: "Doe",
email: "[email protected]",
});
// Create a payment instrument (requires tokenId from client-side)
const paymentInstrument = await easy.createPaymentInstrument({
type: "PAYMENT_CARD",
name: "Primary Card",
identityId: customer.data.id,
tokenId: "tok_abc123", // From client-side tokenization
});
// Process a payment
const transfer = await easy.createTransfer({
amount: 2500, // $25.00 in cents
currency: "USD",
source: paymentInstrument.data.id,
statement_descriptor: "Purchase from Store",
});
console.log("Payment processed:", transfer.data.id);
Next Steps
- Explore the API Reference to learn about all available methods
- Check out Integration Examples for real-world patterns
- Review TypeScript Support for type definitions