Send your first SMS with Node.js & Twilio🚀

Send your first SMS with Node.js & Twilio🚀

·

1 min read

In this article, I will show you how we can send SMS with NodeJs and Twilio.

Node.js is an open-source, cross-platform, back-end JavaScript runtime environment that runs on the V8 engine and executes JavaScript code outside a web browser.

Approach

There are so many services and integrations available today that can help you integrate your code with SMS, Whatsapp chats and email services.

But today, I am going to use Twilio because it is quite simple and can be integrated with so many programming languages easily.

So first, create your free account on Twilio and get your Account SID and Auth Token to authorize your requests to the Twilio server.

Steps

Create a node app

initialise a node app with npm init or yarn init and make necessary changes.

Install the twilio package

read more on npmjs.com

npm install twilio

Add the following code to your app.js file

const accountSID = YOUR_TWILIO_SID;
const accountToken = YOUR_TWILIO_AUTH_TOKEN;

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

// send a sms
client.messages.create({
    body: 'Hi, this is a test sms!',
    from: 'your-provided-phone-number-by-twilio',
    to: 'the-recipient-phone-number'
}).then(message => console.log(message));

And that’s it, now run the code to send SMS.


I hope you find this article useful and if it was then please consider signing in for the newsletter.

Â