Twilio Sending messages in Node.js


Twilio allows you to send and receive text messages with Node.js by using the twilio-node library to make calls. This guide assumes you've already setup an account with Twilio and have your account SID and the authentication token from the Twilio Console.


toA valid phone number to receive the message
fromA Twilio number that is assigned to you
bodyThe body of the text message limited to 1600 characters
StatusCallbackA URL that Twilio posts to when a message status changes
maxPriceSet the maximum price of a message
validityPeriodThe number of seconds the message will remain in the Twilio queue
provideFeedbackBoolean value, when set to true
mediaUrlA URL containing a gif, png or jpeg content that will be sent with the message


2.0 SDK Deprecation

Twilio has two versions of the twilio-node module, a 2.0 SDK and a 3.0 SDK. It is recommended to use the 3.0 SDK as the 2.0 SDK will be deprecated on the 8/31/2017.

Deprecation notice: New functionality will only be added to the new library (Node Helper Library 3.x). The old library (2.x) will be officially supported until 8/31/2017. After that day, Twilio will stop providing bug fixes and Support might ask you to upgrade before debugging issues.

Parameter Reference

You can refer to the Twilio REST documents for a more detailed description. Twilio also has a JSdocs which can be used as a reference.

Sending Your First Message

Installing The Node Module

You can install this module by running the command below in your project directory:

npm install twilio

Sending Your Message

const accountSID = ''; // Obtained from the Twilio Console
const authToken = '';   // Obtained from the Twilio Console

const client = require('twilio')(accountSID, authToken);

    to: '',  // Number you want to send to
    from: '', // From a valid Twilio number
    body: 'Hello, from Stack Overflow', // What appears in the text message
.then((message) => console.log(message.sid));