Send an SMS Message with Node.js SDK

Note:

Before you can get started, you need the following already set up:

Learn how to quickly send SMS messages in a Node.js application with the Sinch Node.js SDK.

Steps:
  1. Set up your Node.js application
  2. Send your first SMS message

Set up your Node.js application

To quickly get started setting up a simple client application using the Node SDK:

  1. If you haven't already, clone the sinch-sdk-node-quickstart repository.
  2. Navigate to the templates/client folder.
  3. Open a command prompt or terminal and run the following command to install the necessary dependencies:
    Copy
    Copied
    npm install
  4. Open the .env file. Using the access key credentials from your Sinch Customer Dashboard, populate the following fields with your values:
FieldDescription
SINCH_PROJECT_IDThe unique ID of your Project.
SINCH_KEY_IDThe unique ID of your access key.
SINCH_KEY_SECRETThe secret that goes with your access key.
Note: For security reasons, this secret is only visible right after access key creation.
Note:
If you're sending SMS messages, ensure you set your region in the SMS_REGION field.
  1. Save the file.

Modify your application

  1. Navigate to the /templates/client/src/sms/ folder and open the snippet.js file. Replace the existing content within that file with the snippet.js code provided on this page. That code is also found here if you want to just replace the file.
  1. The code provided in snippet.js includes default parameters. If you want, you can replace the following values for these parameters with your own values:
ParameterYour value
YOUR_sinch_phone_numberAny number you've assigned to your Sinch account. Find the number on your Sinch dashboard by clicking the service plan ID link and scrolling to the bottom of the page.
YOUR_recipient_phone_numberThe phone number to which you want to send the test SMS message.

Ensure you save your file.

Send your first SMS message

Now you can execute the code and send your test SMS message.

Run the following command:

Copy
Copied
node src/app.js

You should receive a text to the phone number you entered and you'll see a response in your terminal or command prompt. You did it!

Next steps

The code you used in the snippet.js file sends a POST request to the Sinch API /batches endpoint to send the SMS message. Click here to read more about the batches endpoint.

Additional resources

We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.