Send an SMS Message with Node.js SDK
Note:
Before you can get started, you need the following already set up:
- Set all SMS API configuration settings.
- NPM and a familiarity with how to install packages.
- Node.js and a familiarity with how to create a new app.
Learn how to quickly send SMS messages in a Node.js application with the Sinch Node.js SDK.
Set up your Node.js application
To quickly get started setting up a simple client application using the Node SDK:
- If you haven't already, clone the sinch-sdk-node-quickstart repository.
- Navigate to the
templates/client
folder. - Open a command prompt or terminal and run the following command to install the necessary dependencies:
npm install
- Open the
.env
file. Using the access key credentials from your Sinch Customer Dashboard, populate the following fields with your values:
Field | Description |
---|---|
SINCH_PROJECT_ID | The unique ID of your Project. |
SINCH_KEY_ID | The unique ID of your access key. |
SINCH_KEY_SECRET | The 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.- Save the file.
Modify your application
- Navigate to the
/templates/client/src/sms/
folder and open thesnippet.js
file. Replace the existing content within that file with thesnippet.js
code provided on this page. That code is also found here if you want to just replace the file.
- 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:
Parameter | Your value |
---|---|
YOUR_sinch_phone_number | Any 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_number | The 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:
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 thesnippet.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
- Explore the API specification to test more endpoints.