
Index
How to Send SMS Messages with Node.js Step by Step [Practical Guide]
Nowadays, where communication is instant, sending text messages through Node.js has become a very effective way to interact with clients and users. SMS messages arrive within seconds and are usually read immediately, making them a very powerful communication channel.
In this article, we show how to perform the SMS integration with Node.js. A step-by-step guide with examples and everything you need to start sending your first SMS messages from your application.
Introduction to the guide on how to send SMS with Node.js
SMS communication is one of the most effective methods to ensure that an important message reaches the user directly. By incorporating SMS sending in Node.js applications, it is possible to design automated flows for system alerts, appointment reminders, or transaction notifications, with full traceability and speed.
The SMS messaging service API from LabsMobile provides a secure environment based on JSON requests over HTTPS and authentication via token, making it easy to integrate into projects of any scale. Below, we describe the main use cases and requirements needed to start implementing this functionality easily.
Why use Node.js to send SMS?
Node.js is one of the most widely used technologies in backend and real-time application development. Its asynchronous nature and vast package ecosystem make it an ideal tool for integrating external services, including SMS messaging. Thanks to libraries such as Axios or modern HTTP APIs, implementation can be straightforward and scalable.
- Execution speed: Ideal for real-time applications that need to send SMS messages instantly.
- Ease of integration: You can use libraries like
axios(ornode-fetch) to make HTTP requests to the LabsMobile SMS API. - Scalability: Suitable for applications that need to send large volumes of SMS messages.
- Portability: Your code can run in different environments (servers, serverless functions, containers, etc.) without major changes.
Prerequisites
- Active account on LabsMobile (username and API token). Register at LabsMobile
- Node.js installed on your system (version 14 or higher)
- HTTP library such as
axiosto send HTTP requests (npm install axios) - Secure connection (HTTPS) for all requests to the LabsMobile API
Steps to send SMS with Node.js
- Prepare credentials: Generate the API token in your LabsMobile Control Panel, obtain your API credentials (
usuario:token), and encode them in Base64 for theAuthorizationheader. - Define the API URL: Use
https://api.labsmobile.com/json/sendthrough a POST request. - Create the JSON payload: Include fields such as sender (
tpoa), recipients, and message text. - Send the HTTP request: Use
axios.postwith headersContent-Type: application/jsonandAuthorization: Basic <credentials>. - Process the response: Validate the
codefield in the JSON response to confirm whether the message was successfully sent.
Example of JSON payload
{
"message": "Your verification code is 1234",
"tpoa": "MySender",
"recipient": [
{ "msisdn": "34123456789" }
]
}
Suggested modular code
const axios = require('axios');
async function enviarSMS({ usuario, token, tpoa, destinatarios, mensaje, opciones = {} }) {
const credenciales = Buffer.from(${usuario}:${token}).toString('base64');
const url = 'https://api.labsmobile.com/json/send';
const payload = {
message: mensaje,
tpoa: tpoa,
recipient: destinatarios.map(msisdn => ({ msisdn })),
...opciones
};
const headers = {
'Content-Type': 'application/json',
'Authorization': Basic ${credenciales}
};
try {
const response = await axios.post(url, payload, { headers });
return response.data;
} catch (error) {
// Handle errors: network, API response, etc.
throw error;
}
}
This modular approach allows you to reuse the logic for different scenarios by simply changing the parameters you send.
Integration examples using the modular code
- Welcome message:
enviarSMS({
usuario: 'miUsuarioLabsmobile',
token: 'miToken',
tpoa: 'MiApp',
destinatarios: ['34123456789'],
mensaje: 'Bienvenida Lucía, gracias por unirte a nuestra plataforma!'
})
.then(res => console.log('SMS enviado:', res))
.catch(err => console.error('Error:', err));
- Order confirmation:
enviarSMS({
usuario,
token,
tpoa: 'MiTienda',
destinatarios: ['34111222333'],
mensaje: 'Hola Carlos, tu pedido de "Zapatillas deportivas" fue confirmado y está en preparación.'
})
.then(...)
.catch(...);
- Bank transaction alert:
const monto = 1250.00;
const tarjeta = "****6789";
const celular = "34122334455";
enviarSMS({
usuario,
token,
tpoa: 'BancoSeguro',
destinatarios: [celular],
mensaje: `Alerta: se realizó un cargo de $${monto.toFixed(2)} en tu tarjeta ${tarjeta}.`
})
.then(...)
.catch(...);
Common errors when sending SMS with Node.js
- Error 401 (Unauthorized): Incorrect credentials or expired token.
- Error 400 (Bad Request): Invalid JSON structure or malformed number.
- Network error: Check that the server has proper HTTPS access and DNS configuration.
Security and best practices
- Always use HTTPS to encrypt requests.
- Store credentials in environment variables or secure systems (never in code).
- Prefer POST with JSON over GET to avoid exposing sensitive data.
- Handle errors by validating that
code === "0"to confirm success and detect other possible codes. - Enable filters in your LabsMobile account: IP restriction, duplicate prevention, country filters.
- Perform tests in sandbox or test mode before moving to production.
Common use cases
- Identity verification / OTP / 2FA: Send temporary one-time codes for login, password recovery, or device registration.
- Transactional notifications: Purchase confirmations, status updates, shipping, invoicing, or returns.
- Automated reminders: Medical appointments, events, upcoming payments, renewals.
- Security alerts: Notifications about suspicious activity, account changes, or unauthorized access.
- Internal operational workflows: System alerts, critical failures, resource monitoring, or scheduled tasks.
- Responsible relationship marketing: Limited promotions, consent-based and segmented campaigns.
- Integration with CRM / ERP / e-commerce: Trigger SMS when a customer’s status changes, renewals, order tracking, etc.
- Inbound messages / virtual number: If your LabsMobile account includes a virtual number, you can receive and process replies via API. For more information, see the inbound message section in the LabsMobile SMS API Documentation.
Conclusion
Implementing SMS sending with Node.js and LabsMobile is an efficient and secure process that enhances instant communication with your users. With this guide, modular code, and included examples, you can integrate this functionality into your Node.js application within minutes.
Discover how SMS sending with Node.js can optimize your communication processes. Contact us and take the next step towards efficiency with LabsMobile!
Start sending SMS from your Node.js application today with LabsMobile. Create your free account and test the API in just minutes.
Links for more API information

Our team advises you
Interested in our services?
Our managers and technical team are always available to answer all your questions about our SMS solutions and to advise you on the implementation of any action or campaign.
Contact us

