Following is a pseudocode of what I am doing
Javascript
1) Make XMLHttpRequest GET
Request to get data from a server
2) Parse the response received and and make a string of the desired format
3) Make XMLHttpRequest POST
Request to send this new string to a PHP script
PHP
4) Parse this received string
5) Send this string to a mqtt broker
For now, my Javascript code is written in a HTML file and I run this entire process in a webpage. In order to run this continuously, I have to keep this webpage open in my browser all the time(I cannot shut my PC at all). But I do not want to keep my system up and running all the time. So I am thinking of running this entire process on a server using crontab
. But these are the following issues I am encountering.
1) To run my JS on the server, I used NodeJS to run it. But NodeJS has its own XMLHttpRequest alternative, which I tried, but cannot even get it to do my first step.
My doubt is, even if I get NodeJS to successfully do http requests, can NodeJS run my the entire process since it also involves PHP?
2) I thought of changing my entire JS code to a PHP code, because crontab cam run PHP scripts.
My doubt is, can I do the XMLHttpRequest in PHP like I am doing in the JS?