Send a Text Message using JavaScript/Node.js in 30 seconds with Twilio
Time to read: 2 minutes
You’re building a Node app and you need to send text messages. Did you know it only takes you 30 seconds? Here’s a video to show you how quick it is to get started:
Video: How To Send SMS In Node 30 Seconds
Note: The code below has been updated to use the latest version of the helper library.
If you want to run that code, open a file called index.js
, copy and paste that code and run the following in your terminal (from the same directory the file is saved in):
What just happened?
Now let’s walk through what happened in the video step by step.
Install the Twilio helper library for Node using npm.
Open up a Node session by typing node
in your terminal and require the twilio
library.
Instantiate a REST client using your account sid and auth token, available in your Twilio account Console:
In the video, I have those stored in environment variables to avoid showing my credentials to you. You can do that like so:
You’ll now need three things:
- The number you are sending the message to
- The Twilio number you are sending the message from
- The body of the message
With these you can now send a text message by calling client.sendMessage()
:
Now just wait for the magic to happen!
We can’t wait to see what you build
You’ve sent a text message and now you’re ready to take on the world. Check out the Twilio REST API documentation and the documentation for working with the Node helper library to see what else you can do. You can also take a look at our tutorials to see more examples such as: sending SMS notifications, masking phone numbers for user privacy or two factor authentication for user security.
I’m looking forward to seeing what you all build. Feel free to reach out and share your experiences or ask any questions.
- Email: sagnew@twilio.com
- Twitter: @Sagnewshreds
- Github: Sagnew
- Twitch (streaming live code): Sagnewshreds
Related Posts
Related Resources
Twilio Docs
From APIs to SDKs to sample apps
API reference documentation, SDKs, helper libraries, quickstarts, and tutorials for your language and platform.
Resource Center
The latest ebooks, industry reports, and webinars
Learn from customer engagement experts to improve your own communication.
Ahoy
Twilio's developer community hub
Best practices, code samples, and inspiration to build communications and digital engagement experiences.