Get Started

Install the Twilio Node Helper Library

The twilio-node helper library lets you write Node.js code to make HTTP requests to the Twilio API.

This library is open source, so if you find a feature missing or a bug, we encourage you to contribute back to the twilio-node project hosted on Github.

More Documentation

The Rest API Documentation has examples written in Node.js for every kind of action you could take with the Twilio API. You should start there if you know what you want to do with the Node.js library.

You may also want to refer to the twilio-node specific documentation for more details about the functions contained in the module.

Installation

The easiest way to install twilio-node is from NPM. You can run the below command to install the library:

npm install -g twilio

Or, you can clone the source code for twilio-node, and install the library from there.

git clone git@github.com:twilio/twilio-node
cd twilio-node

Then in your code:

require("path/to/twilio-node/lib");

Testing your installation

Try sending yourself an SMS message, like this:

sendSms.js
// Your accountSid and authToken from twilio.com/user/account
var accountSid = 'AC32a3c49700934481addd5ce1659f04d2';
var authToken = "";
var client = require('twilio')(accountSid, authToken);

client.messages.create({
    body: "Jenny please?! I love you <3",
    to: "+14159352345",
    from: "+14158141829"
}, function(err, message) {
    process.stdout.write(message.sid);
});

Using the Module

Refer to the twilio-node specific documentation for details about the functions contained in the module.

Handling Exceptions

If the Twilio API returns a 400 or a 500 level HTTP response, the twilio-node library will include information in the error parameter of the callback. 400-level errors are normal during API operation ("Invalid number", "Cannot deliver SMS to that number", for example) and should be handled appropriately.

var twilio = require('twilio');
var client = new twilio.RestClient(accountSid, authToken);

client.messages.create({
    to:'+16512223344',
    from:'TWILIO_NUMBER',
    body:'Hello World'
}, function(error, message) {
    if (error) {
        console.log(error.message);
    }
});

Getting help

Still running into problems?