Node.js SDK Getting Started
The Acme Node.js SDK provides a convenient way to interact with the API from Node.js applications.
Installation
Section titled “Installation”npm install @acme/sdkQuick Start
Section titled “Quick Start”const Acme = require('@acme/sdk');
// Initialize the clientconst acme = new Acme('sk_live_abc123...');
// List usersconst users = await acme.users.list({ limit: 10 });users.data.forEach(user => { console.log(`${user.name}: ${user.email}`);});
// Get a specific userconst user = await acme.users.get('usr_abc123');console.log(user.name);
// Create a new userconst newUser = await acme.users.create({ email: 'alice@example.com', name: 'Alice Smith'});console.log(`Created user: ${newUser.id}`);Configuration
Section titled “Configuration”const Acme = require('@acme/sdk');
const acme = new Acme('sk_live_abc123...', { timeout: 30000, // Request timeout in ms maxRetries: 3 // Number of retry attempts});Error Handling
Section titled “Error Handling”const Acme = require('@acme/sdk');
const acme = new Acme('sk_live_abc123...');
try { const user = await acme.users.get('usr_invalid');} catch (error) { if (error.code === 'not_found') { console.log('User not found'); } else if (error.code === 'rate_limit') { console.log(`Rate limited. Retry after ${error.retryAfter}s`); } else { console.log(`API error: ${error.message}`); }}TypeScript Support
Section titled “TypeScript Support”The SDK includes TypeScript definitions:
import Acme, { User, AcmeError } from '@acme/sdk';
const acme = new Acme('sk_live_abc123...');
const user: User = await acme.users.get('usr_abc123');console.log(user.email);