Send SMS with Node.js

To send an SMS from Node.js, call the curl-sms API with the built-in fetch (Node.js 18 or newer). No npm package needed.

Example

// send-sms.mjs
export async function sendSms(receiver, body) {
  const res = await fetch('https://curl-sms.com/api/sms/send', {
    method: 'POST',
    headers: {
      Authorization: `Bearer ${process.env.CURLSMS_KEY}`,
      'Content-Type': 'application/json',
    },
    body: JSON.stringify({ receiver, body }),
    signal: AbortSignal.timeout(10_000),
  });
  const data = await res.json();
  if (res.status !== 202) throw new Error(`${data.error.code}: ${data.error.message}`);
  return data;
}

const sms = await sendSms('+4915123456789', 'Hello from Node.js');
console.log(sms.id, sms.status); // 01JDQ8M3… queued

Run it with CURLSMS_KEY=cs_test_… node send-sms.mjs. A test key runs every check but sends nothing and costs nothing.

What you get back

202 Accepted with the SMS: id, status (queued, then sent and delivered), segments, encoding, price. Errors come as { error: { code, message } }, for example invalid_receiver or rate_limited; see error codes.

Tips

  • Retries without duplicates: add an 'Idempotency-Key' header, e.g. the order or job ID. Same key and body within 24 hours means the SMS goes out once.
  • Status via webhook: the webhook guide explains the events; the docs have the signature check for Node.js and Express.
  • Deno, Bun, edge functions: the same fetch call works there too. Read the key from the platform's secret store instead of process.env.
  • Rate limit: 10 requests per second per key. For many receivers with the same text send one request with receivers (up to 100).