Sending SMS using NEXMO API in Node.js

14 Feb, 2020
Introduction: SMS is a common method of sending short messages between cell phones, but these SMS can be sent using API in Node.js. Now there are lots of API in the market for sending SMS like Twilio, Exotel, etc to the user but the popular among them is Nexmo.
Features of NEXMO: Integrating this module in your code is very simple and efficient. Using Nexmo module users can send SMS and also use Nexmo voice APIs for sending voice calls.
Introduction:
It’s easy to get started and easy to use.It is widely used and popular module for sending SMS.User can send SMS to desired mobile number fastly and efficiently.
It’s easy to get started and easy to use.
It is widely used and popular module for sending SMS.
User can send SMS to desired mobile number fastly and efficiently.
Installation of Nexmo module:
You can visit the link to Install nexmo module. You can install this package by using the following command.npm install nexmoAfter installing nexmo you can check your nexmo version in command prompt using the command.npm version nexmoAfter that, you can create a folder and add a file. For example index.js. To run this file you need to run the following command.node index.jsRequiring module: You need to include nexmo module in your file by using these lines.const Nexmo = require('nexmo');Filename: index.js// Include nexmo moduleconst Nexmo = require('nexmo');   const nexmo = new Nexmo({    apiKey: 'YOUR_API_KEY',    apiSecret: 'YOUR_API_SECRET_KEY',});  // Initialize with sender and reciever// mobile number with text messageconst from = 'sender_name';const to = 'reciever_number';const text = 'Greetings from Geeksforgeeks';  nexmo.message.sendSms(from, to, text,                function(error, result) {             // If some error occured    if(error) {        console.log("ERROR", error)    }          // If message is sent successfully    else {        console.log("RESULT", result)    }});Steps to run the program:The project structure will look like this:Make sure you have installed nexmo using following commands:npm install nexmoRun index.js file using below command:node index.jsIf error occurs, then following message will be displayed:My Personal Notes
arrow_drop_upSave
You can visit the link to Install nexmo module. You can install this package by using the following command.npm install nexmo
npm install nexmo
After installing nexmo you can check your nexmo version in command prompt using the command.npm version nexmo
npm version nexmo
After that, you can create a folder and add a file. For example index.js. To run this file you need to run the following command.node index.js
node index.js
Requiring module: You need to include nexmo module in your file by using these lines.const Nexmo = require('nexmo');
const Nexmo = require('nexmo');
Filename: index.js
// Include nexmo moduleconst Nexmo = require('nexmo');   const nexmo = new Nexmo({    apiKey: 'YOUR_API_KEY',    apiSecret: 'YOUR_API_SECRET_KEY',});  // Initialize with sender and reciever// mobile number with text messageconst from = 'sender_name';const to = 'reciever_number';const text = 'Greetings from Geeksforgeeks';  nexmo.message.sendSms(from, to, text,                function(error, result) {             // If some error occured    if(error) {        console.log("ERROR", error)    }          // If message is sent successfully    else {        console.log("RESULT", result)    }});
Steps to run the program:
The project structure will look like this:Make sure you have installed nexmo using following commands:npm install nexmoRun index.js file using below command:node index.jsIf error occurs, then following message will be displayed:
The project structure will look like this:
Make sure you have installed nexmo using following commands:npm install nexmo
npm install nexmo
Run index.js file using below command:node index.js
node index.js
If error occurs, then following message will be displayed:
Node.js-Misc
Technical Scripter 2019
Node.js
Technical Scripter
Web Technologies
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
JWT Authentication with Node.js
Installation of Node.js on Windows
Difference between dependencies, devDependencies and peerDependencies
Mongoose Populate() Method
Mongoose find() Function
Top 10 Projects For Beginners To Practice HTML and CSS Skills
Difference between var, let and const keywords in JavaScript
How to insert spaces/tabs in text using HTML/CSS?
How to fetch data from an API in ReactJS ?
Differences between Functional Components and Class Components in React