Node.js SDK

The official Node.js and TypeScript client sends an SMS with one call. No runtime dependencies, full types, ESM and CommonJS, for Node.js 20 or later.

Install

npm install curl-sms

Send an SMS

With ES modules or TypeScript:

import { CurlSMS } from 'curl-sms';

const sms = new CurlSMS({ apiKey: 'cs_test_example' }); // or set CURLSMS_API_KEY

const message = await sms.send({ receiver: '+4915123456789', body: 'Hello from curl-sms' });
console.log(message.id, message.status); // 01JDQ8M3V6R1T5ZK2X9N4C7B0A queued

With CommonJS:

const { CurlSMS } = require('curl-sms');

const sms = new CurlSMS({ apiKey: 'cs_test_example' });
sms.send({ receiver: '+4915123456789', body: 'Hello from curl-sms' }).then((m) => console.log(m.status));

Test keys (cs_test_…) run all checks, send nothing and cost nothing. Swap in a live key (cs_live_…) when you are ready; your code stays the same.

Up to 100 receivers (receivers: [...]) and scheduled sending (sendAt) work with the same send call.

Configuration

Keep the key out of your code: without apiKey the client reads it from the environment variable CURLSMS_API_KEY.

export CURLSMS_API_KEY=cs_test_…
const sms = new CurlSMS({
  timeout: 30_000, // per attempt, in milliseconds
  maxRetries: 2, // retries after network errors, timeouts, 429 and 5xx
  language: 'en', // language of error messages: 'en' or 'de'
});

Without an API key the constructor throws an error explaining how to set one.

Error handling

Every failure is a CurlSMSError with the HTTP status and the error code:

import { CurlSMSError } from 'curl-sms';

try {
  await sms.send({ receiver: '12345', body: 'Hi' });
} catch (error) {
  if (error instanceof CurlSMSError) console.error(error.status, error.code); // 422 invalid_receiver
}

Network errors, timeouts, 429 and 5xx are retried automatically. Every send carries an idempotency key, so a retry never sends an SMS twice.

More

The client also covers estimate, get, cancel, list and account, and verifies webhooks with parseWebhook. All methods with examples are in the README on GitHub; every field is in the API reference.