# Send an SMS Message with Node.js Note: Before you can get started, you need the following already set up: - - [Node.js](https://nodejs.org/en/) and a familiarity with how to create a new app. Quickly send SMS messages in a Node.js application with the Sinch SMS API. Steps: 1. [Set up](#set-up-your-nodejs-application) your Node.js application. 2. [Send](#send-your-first-sms-message) your first SMS message. ## Set up your Node.js application First we'll create a Node project using npm. This creates a package.json and the core dependencies necessary to start coding. To create the project, do the following steps: 1. Create a folder called `send-sms-app` 2. Navigate into the folder you created and run the following command. ```shell npm init ``` This command adds the package.json file. You will be prompted to provide values for the fields. For this tutorial, you can simply accept the default values and press enter at each stage. 3. Add the axios package with npm to generate the necessary dependencies. ```shell npm install axios ``` ### Create your file Create a new file named `index.js` in the project and paste the provided "Send an SMS message" code into the file. Send an SMS message // Find your Service Plan ID and API Token at dashboard.sinch.com/sms/api/rest // Find your Sinch numbers at dashboard.sinch.com/numbers/your-numbers/numbers const SERVICE_PLAN_ID = 'YOUR_servicePlanId'; const API_TOKEN = 'YOUR_API_token'; const SINCH_NUMBER = 'YOUR_Sinch_virtual_number'; const TO_NUMBER = 'RECIPIENT_number'; const REGION ='YOUR_region' const SINCH_URL= 'https://'+REGION+'.sms.api.sinch.com/xms/v1/' + SERVICE_PLAN_ID + '/batches' const axios = require('axios') const headers={'Content-Type': 'application/json', 'Authorization': 'Bearer ' + API_TOKEN} const payload = JSON.stringify({ from: SINCH_NUMBER, to: [TO_NUMBER], body: 'Programmers are tools for converting caffeine into code. We just got a new shipment of mugs! Check them out: https://tinyurl.com/4a6fxce7!' }) axios.post(SINCH_URL, payload, { headers }) .then(response => console.log(response.data) ).catch(error => console.error('There was an error!', error.response) ); ### Fill in your parameters 1. Assign your values to the following parameters: | Parameter | Your value | | --- | --- | | `SERVICE_PLAN_ID` | The service plan ID found on your [Sinch Build Dashboard](https://dashboard.sinch.com/sms/api/rest). SMS > APIs > REST configuration | | `API_TOKEN` | The API token found on your [Sinch Build Dashboard](https://dashboard.sinch.com/sms/api/rest). SMS > APIs > REST configuration > Click Show to reveal your API token. | | `SINCH_NUMBER` | Any number you've assigned to your Sinch account. Find the number on your [Sinch Build Dashboard](https://dashboard.sinch.com/sms/api/rest) by clicking the service plan ID link and scrolling to the bottom of the page. | | `TO_NUMBER` | The phone number to which you want to send the test SMS message. | | `REGION` | Double check that the region is correct on your base URL. Learn more about [regional options here](/docs/sms/api-reference#base-url). | 2. Then, save the file. ## Send your first SMS message Now you can execute the code and send your test SMS message. Run the following command: ```shell node index.js ``` ## Next steps The code used in the index.js file sends a POST request to the Sinch SMS API `/batches` endpoint to send the SMS message. [Read more about the batches endpoint](/docs/sms/api-reference/sms/batches). - [Learn how to recieve SMS](/docs/sms/getting-started/node/receive-sms) ## Additional resources - Visit our [API specification](/docs/sms/api-reference/) to test more endpoints.