Guide · updated November 2026

Receive SMS verification codes with Node.js

By the Noir SMS team3 min read

Quick answer

Node 18+ has fetch built in, so you can call the Noir SMS API without dependencies. Send POST /api/v1/numbers with service and country and a Bearer key, then poll GET /api/v1/numbers/{id} until status is received and read sms[0].code. Errors come back with a stable error.code like insufficient_balance or no_numbers that you can switch on.

Here's a small, dependency-free helper you can drop into a script, a worker or a backend route.

Requirements

  • Node.js 18 or newer (for global fetch and top-level await in .mjs files).
  • An API key from the API page in your dashboard, in NOIRSMS_KEY.

The code

javascript
const API = 'https://noirsms.com/api/v1';
const H = { Authorization: `Bearer ${process.env.NOIRSMS_KEY}`, 'Content-Type': 'application/json' };

async function call(path, opts = {}) {
  const r = await fetch(API + path, { headers: H, ...opts });
  const body = await r.json();
  if (!r.ok) throw Object.assign(new Error(body.error?.message), { code: body.error?.code, status: r.status });
  return body;
}

const buy = (service, country) =>
  call('/numbers', { method: 'POST', body: JSON.stringify({ service, country }) });

async function waitForCode(id) {
  for (;;) {
    const n = await call(`/numbers/${id}`);
    if (n.status === 'received') return n.sms[0].code;
    if (n.status === 'canceled' || n.status === 'expired') return null;
    await new Promise((r) => setTimeout(r, 4000));
  }
}

const n = await buy('wa', 'gb');
console.log('Number:', n.phone);
console.log('Code:', await waitForCode(n.id));

In production

  • Prefer the sms.received webhook over polling for many numbers at once.
  • Verify the X-NoirSMS-Signature header on every webhook.
  • Log the number id with each order so you can cancel or finish it later.

Use it responsibly

Use the API only for your own legitimate accounts or apps you're authorized to test, and make sure your customers follow the same Acceptable Use Policy.

Frequently asked questions

Does it work in Cloudflare Workers or Deno?

Yes. The example only uses fetch, which those runtimes provide.

What country codes are used?

2-letter ISO codes in lowercase, such as us, gb and ca.

Services in this guide

Keep reading

Ready to receive your code?

Create a free account, add funds from $5 and get your first verification code in under a minute.