Sample code for sending an SMS message using Node.js and Express with the Vonage SMS API.
For a step-by-step tutorial, follow along the accompanying article.
-
Clone this repository.
-
Run
npm install
in your project folder. -
Provide string values for the environment variables in the
.env
file.
Find your API key and secret in your Vonage Dashboard. You can choose a virtual number from the Your Numbers section. -
Run
node index.js
. -
Use Postman or a similar service to make a POST request to
https://localhost:3000/send
with the following JSON object in the request body:
{
"toNumber": "YOUR_MOBILE_PHONE_NUMBER",
"message": "Taco tracks on every corner! 🌮🌮"
}
Replace YOUR_MOBILE_PHONE_NUMBER
with your personal number in E. 164 format, for example: 447401234567.