How to send SMS using NodeJS for Free? - (with Fast2sms - India)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello there everyone and welcome to coding ounce in this video we will be learning how to send a mobile SMS using nodejs and fast to SMS so without wasting much time let us begin so everyone just a quick overview of what is already done here and we have credulous an SMS named folder for our project and open the same folder in Microsoft Visual Studio code so let's begin with creating our node project by running the command NPM in it to initialize our node project hit enter and keep hitting Enter for all the questions because it wouldn't matter much for this tutorial so you can see now that a package dot JSON file is created over there and it says that our main file will be indexed or Chiu's so let's create the indexed or chase file and now we can install the package required so we can we are going to make a extra solar over here so we'll be installing Express power in the command NPM install Express and hit enter as you'll see it takes a few seconds to install Express in your project fair enough sticking awkward than usual but now it is installed so now we have expressed available to all project and I recommend you to download one more snippet just go in your extensions and search for JavaScript you'll see a snippet named JavaScript PSX code snippets by charalampos and categories so install this and it'll be really helpful because I'll be using a few quick things for instance I'll be using this our EQ and hit enter so you can see it says cost Express require Express this is a snippet to fastly require any package in your node project so now we have Express here we can have the Const and we can create an app for our from our Express instance and now we can make our app to less on port 3000 and whenever it listens we can say 2 o'clock somewhere is sorry anything what it comes over there server is listening on port 3000 if you save this file go to your terminal and run the command note space in next or JSA it's a it's server is listening on port 3000 but to make this development process a more efficient and watch this file for changes we can install another package and which is called as node launch so when the command npm install node want and since it is a developer dependency we'll say set that save that and it enter you'll see it takes a few second but as soon as it install you'll see the real purpose of it now we can go in our package store JSON file and change the script and create a script for our developer / product developer use so which is we can create a script for dev start and make the debit script to be node one space indexed or chair so basically whenever you run the scape that start it will start watching the indexed or chase file for changes and run the node or over it so now you can see a node 1 is still not installed which is bad and bad because we have changed the practice or JSON file kind of played with that now we need to do that again so Brenda's come on and wait for it to install node more in our system so now Norman is also installed in our system and our script is also ready over there so we can start listening and watching the index that's cheers fun run the command npm run dev start and you can see whenever I change anything on this index to chase file for instance I'll change the P the capital P it will restart the server for us and automatically publish the changes now we also want our server to listen for get requests on / which is actually the home page and then we need a callback function for the sket which is a request which takes two parameters request and response and then we can send a response which is hello save this file you can see the server is part of metal restarted again you can go to your browser and create a get request on the port its housing for localhost / which gives hello as the output now that our server is listening for get requests and also can listen for post requests of the future we can create and set up a view engine for our project so let's open the command prompt and run the command n p.m. in stops we have to close the server and run the command npm install EGS we'll be using EGS throughout this tutorial which is the abbreviation for embedded KS so it is pretty much a HTML like few engine for node and if you don't use it I'll show you it is very very easy to use it and we'll be using it just like HTML for this project so now we can go and residence we can ask our server to actually use the view engine which is EGS okay so it makes sense we asked me our server app to use a new engine which is PJs and now we create a folder for our views and we can have our first view which will be the pretty much the only view we'll be using for this project index for changes EJ's nextdoor aegis now if you not do not use Emmet I recommend you go to extensions and install Emmet which is very useful here it is and it is I guess it is it comes in built with Microsoft Visual Studio code if it does not you can just simply install it from the extension store so with Emmet you can have this exclamation mark hit enter and it creates this pretty small boilerplate for your project you can change the title to message sender okay I'm including a simple app and now we will be creating our form for sending the message so let's have a form and the action will be send message looks sliced inside the form we will need a phone group so this is again an abbreviation dart form group creates a division with form group as a class and then we can have input not input rather a label first for number and it says until number then we need an input let's have a text type input for the number give it an ID number and a name of number then we can have another form group for our message enter get the label ready this is for our message say enter message then we have the input gain text type the name will be message ID will be message and we will need a submit button over here so we can have an input submit the value will be send message so if I save this file and go to our in extra chairs and rather than saying rescue response store sent hello will saying this spawn start render so whenever there is a respond render our view which is indexed thought each now if you go over there and run yourself were again for development in NPR and then start you can see in the browser on reloading and we have a problem over there it says use and we are using but rather we should not use we should set we are setting I'm sorry this is a pretty small mistake I do a lot of times so if you dare the news we need app dot set for overview engine we are setting the viewing and not using the view engine and if you see the node man has already started so are just we know this page and yes there is our farm which is not plea beautiful but that's not the purpose of the studio the purpose of the tutorial was to actually see how we can send message using the back end in our node.js server and not the UI part so I will be keeping my UI as simple as test for this project now we can take this take a post request on this send message for our server so apt outpost for send message and we again need that callback with request and response as the parameters and we are going to use and access the form elements the input values with the request start body but this is not accessible until we turn off URL and extent URL encoding extended so we code here and setup the middleware apt or choose and yes this time it is advert used I'm not doing a mistake you use a produce URL encoded Express taught URL encoded and we say you pass in the property extended to be false and it's done now if you go and lock the requester body and run the server refresh this and pass in some number over there and a message yes this is a nice message but if you send you can see it is reload it's continuously loading but because we have not given a response yet but you can see it is logging the number and the message so we are able to access the sequestered body over there for now we can stop loading the browser so that it doesn't gives an error message over there and we can close our server for now now I'll need you to see what are we going to use to send our message so to send them a message we'll be using this fast - SMS comm which is a which is for India only right now and I'll make sure it doesn't logs in because my order logging so if you see over there you can see it has a free rupees 50 carrier per side up and it is pretty much very much amount of money for your project such as if you want do going for a hackathon or you're creating a school project or a college project you will need some service with some extra features and you don't need thousands of messages 250 messages with 250 rupees you can actually send 250 messages in this service so this is for India now you need we simply need to log in over here and refreshing it so let it read what's my password and login and I am yes I am hiding my phone number so it says invalid password lets me just enter the password and in so you can see the window is pretty clear you can send a message from over here by entering the sender ID and the sender ID here you can actually add a sender ID by buying a sender ID over here for one month or for six month and I can tell you the service is really great so if you are going for a professional project you can go with faster SMS specifically for India but for this video we'll be using this faster SMS and you can send a message from over here and again I'm hiding the number over there so you can send the message and it will simply send the message but this is not our purpose we are going to use no tears to over send our message so I'm gonna tell you something very important we need to have our API key so here you can see this is my API key and this will be used in our project so just copy this let's close this over here right now just close it and we can go to our project and you're going to install dot env which is a package used to hold environment variables API key is truly something which we do not send to the server where the server is located directly and we do not want to float it to over gate also so we create a dot env file which holds our API key and you can set it to this API key and just paste it over there save this file and go to index dot EGS - sorry index ojs to configure our environment so we can do this by requiring the dot env and we can then say that config and now we have access to this API key through process dot e NV dot API key now to send this message we are going to use NPM package named fast to SMS so if you open fast to SMS in NPM jeaious you can see the readme is pretty clear it clearly defines what we have to do to send a message just in solve install fast to SMS using this command which is wrong using this command actually so NPM install fast through SMS and hit enter so it will install fast to SMS in your project and after that we can just use faster SMS with the same way we use it and then we can have the options for for requirement the required options our message however API key and numbers to whom we want to send the message so I'll be using my your phone app to show you that the message is received to my phone number and this will be pretty much it for this video we'll be sending the message using this thing so we don't need to change these things this is what we need to use and we can have the response object and we will be having the response object and we will be descending the scroll logs over there and this really so now that passed us messily is installed we can require it over here so fast - SMS is equals to require sorry fast - SOS save this file and when we say we get this mess Rick post request we can say request that okay not request start rather fast - SMS dot send message and we need to pass in the options the first option was as we can see authorization so we send the authorization which is inside our process dot e and V dot API our Mexico key so if you check the dot env it is API underscore key then we need to pass in the message and the message is a message is in request dot body dot message and then we need to have the numbers and for now we are having a single number but we still need to pass it using an array so we are going to pass it the numbers and it will be in salmon array the first element requested body oh my god body dot number so so now we can actually send a message but we are not yet receiving the object so I'm gonna say cost response is equals to a weight and for a weight we are going to make this call that function a same function now that we have the response object we can actually send back this response object which will tell us if the message is sent or not so we are going to just send the response object and now if you save this file and go to your command prompt and Easter the silver by using NPM growing that start hit enter and now you go back to your message sender and type in your phone number and type the message hey coding outs and click on the send message button you can see in the command problem it says message sent successfully and the object that we have sent back to so or to the request as a response is returned to request ID and the message sent successfully to Nandi any numbers and now as you can see in the screenshot over here in the right side of the screen that the message is received in my phone number so this is how you send a message using pass through SMS API and the fast to SMS package and no chairs just with the two lines of code and guys this is pretty much it for this video if you want me to wake our video on some specific topics of your choice please let me know in the comments below and if you have not subscribed our channel yet please subscribe and hit the bell I can also share this video with your colleagues and like if you love this video and as always thanks for watching
Info
Channel: Coding Owls
Views: 14,735
Rating: 4.6827588 out of 5
Keywords: how to send sms using node js, send sms using node, send sms using node js, send sms using nodejs free, send sms using node js free, fast2sms nodejs, fast2sms node js, send sms with fast2sms, send free sms node, send sms node js free, send sms using node.js free, fast 2 sms, fast 2 sms kya hai, fast 2 sms contact number, twilio node, text message api, how to send text messages using node, nodejs send text message, nodejs send text message free
Id: k0HaX2YXBXE
Channel Id: undefined
Length: 18min 43sec (1123 seconds)
Published: Sat May 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.