Sign In Start Free Trial
Account

Add to playlist

Create a Playlist

Modal Close icon
You need to login to use this feature.
  • Twilio Best Practices
  • Toc
  • feedback
Twilio Best Practices

Twilio Best Practices

By : Rogers
4.5 (4)
close
Twilio Best Practices

Twilio Best Practices

4.5 (4)
By: Rogers

Overview of this book

If you have experience with at least one programming language and are looking to integrate Twilio into your applications, then this book is for you.
Table of Contents (10 chapters)
close
9
Index

Node.js


The twilio-node library is available on npm, which is Node's package manager that is included when you download Node itself.

To install the library, run npm install twilio --save in your project directory, or npm install –g twilio to install it globally across your machine.

In your code, you'll just need to require the library and instantiate a client (client.js):

var account_sid = process.env.TWILIO_ACCOUNT_SID;
var auth_token = process.env.TWILIO_AUTH_TOKEN;
var client = require('twilio')(account_sid, auth_token);

The syntax for sending an SMS from this point onwards is similar to Ruby, using a dictionary of arguments.

However, there is a complication in that Node uses asynchronous requests when contacting the API, meaning that we can't simply save what the method returns to a variable. Instead, we provide a callback that will be invoked with the Message object once it has been sent successfully (send_sms.js):

client.messages.create({
  body: "This is an SMS message.",
  to: "+441708300116...
bookmark search playlist font-size

Change the font size

margin-width

Change margin width

day-mode

Change background colour

Close icon Search
Country selected

Close icon Your notes and bookmarks

Delete Bookmark

Modal Close icon
Are you sure you want to delete it?
Cancel
Yes, Delete