Back to Blog
Language How-Tos

How to Send Bulk SMS in Twilio Using Node.js

Send bulk SMS to a list of recipients in Node.js with proper async handling, rate limiting, and per-message error tracking.

DA
Danial A
Senior Twilio Consultant, Telphi Consulting
June 22, 2026
8 min read
Twilio
Node.js
JavaScript
How-To
Code
How to Send Bulk SMS in Twilio Using Node.js

This tutorial shows how to send SMS to a list of recipients in Node.js using async/await with per-message error handling and rate limiting so you stay within Twilio's default throughput limits. It targets developers building notification, reminder, or alert systems that must reach multiple users at once. You will loop through a recipient array, track results per number, and log a summary of successes and failures without one bad number stopping the whole batch.

Prerequisites and Setup

You need Node.js 14 or higher with the Twilio SDK and dotenv installed via npm install twilio dotenv. Your credentials should be loaded from a .env file as shown in the first SMS tutorial. Prepare recipients as an array of objects with at minimum a phone field in E.164 format; you can build this array from a database query, a JSON file, or a CSV parsed with the csv-parse package. Twilio's default rate limit is one message per second per account on the free tier, so a 1-second delay between sends keeps you safely within that limit.

npm install twilio dotenv

# recipients.js
const recipients = [
  { phone: '+15551234567', name: 'Alice' },
  { phone: '+15559876543', name: 'Bob' },
  { phone: '+15554443322', name: 'Charlie' },
];

module.exports = recipients;

The Complete Code

The script iterates recipients sequentially using a for...of loop combined with await so each message is fully dispatched before the next one starts, keeping throughput predictable. A delay helper wraps setTimeout in a Promise so you can await the pause between sends without blocking the event loop. Each individual messages.create() call is wrapped in try/catch so a failed send logs the error and continues to the next recipient. Printing a summary at the end gives you an immediate count of successes and failures without checking the Twilio Console manually.

require('dotenv').config();
const twilio = require('twilio');
const recipients = require('./recipients');

const client = twilio(
  process.env.TWILIO_ACCOUNT_SID,
  process.env.TWILIO_AUTH_TOKEN
);
const FROM = process.env.TWILIO_PHONE_NUMBER;

const delay = (ms) => new Promise((resolve) => setTimeout(resolve, ms));

async function sendBulk() {
  const results = { sent: [], failed: [] };

  for (const recipient of recipients) {
    try {
      const msg = await client.messages.create({
        body: 'Hi ' + recipient.name + ', this is a message from Telphi.',
        from: FROM,
        to: recipient.phone,
      });
      results.sent.push({ phone: recipient.phone, sid: msg.sid });
      console.log('Sent to', recipient.phone, msg.sid);
    } catch (err) {
      results.failed.push({ phone: recipient.phone, error: err.message });
      console.error('Failed to', recipient.phone, err.code, err.message);
    }
    await delay(1000);
  }

  console.log('Sent:', results.sent.length, ' Failed:', results.failed.length);
  return results;
}

sendBulk();

Testing and Debugging

Start with two or three verified numbers in your recipients list to confirm the loop and error handling work before scaling up to a larger list. If several sends fail with error code 21614, those numbers are landlines that cannot receive SMS; add a Twilio Lookup check before the send loop to filter them out. Check the Twilio Console under Messaging Logs to compare the SIDs in your results against what Twilio received, which is useful for reconciling partial batch failures. If you need higher throughput, upgrade your Twilio account to increase the rate limit and consider using a Messaging Service with a sender pool to distribute volume across multiple numbers.

Taking It Further

Replace the hardcoded recipients array with a database query so the list is always fresh at send time without manual file updates. Add a statusCallback URL to each messages.create() call so Twilio POSTs delivery receipts to your server for per-recipient tracking in your database. Use Promise.allSettled() with a concurrency limiter like p-limit to parallelize sends within your rate limit and reduce total batch time for large lists. Store the batch run results to a database table so you can audit delivery rates and identify problematic numbers over time.

Contact Telphi Consulting to build a high-volume bulk SMS pipeline with carrier compliance, delivery tracking, and reporting dashboards.

Share this article:
0 views

Ready to Transform Your Business Communications?

Get a free consultation with our VoIP experts and discover how we can help you save costs, improve efficiency, and scale your business.

Comments (0)

Join the discussion and share your thoughts (AI-moderated for quality)

Protected by AI moderation

Be the first to comment

No comments yet. Share your thoughts below.