Search code examples
node.jsserverbotspuppeteervps

setting up my puppeteer web scraping bot on vps


I need to set this bot in a windows vps. My bot works fine in a local host but I need to put it in a vps and run it every 12 hours. I don't know how to do it exactly, I am new to servers.

I have searched a lot but couldn't find anything helpful at least on windows. Thanks in advance.


Solution

  • 1 - If nodejs isn't installed on the VPS, install it.

    2 - In the command line / powershell on your Windows VPS, write node -v press enter, if this gives an error press windows + R keys, write rundll32 sysdm.cpl,EditEnvironmentVariables, in the new window, under 'User variables for ...' select Path and click edit and add the nodejs install directory, press OK. Then close and re-open command line / powershell, to check nodejs again.

    2 - Create a test.bat file and enter the following contents using Notepad/Notepad++ :

    cd D:\codework\test\
    
    node index.js
    
    echo finished
    
    • change the directory in this to where your code is located
    • change index.js to whatever you use.
    • put this file where your nodejs code is

    3 - Press windows + R keys, write taskschd.msc to open Task Scheduler, then go to Actions > Create a basic task,

    • enter any name
    • Security options > click Change User or Group.., type either: Network (or System if the task doesn't run) in the popup, press check names then ok.
    • Triggers > select Daily, and the time you want to run it. press ok
    • Actions > New > Start A program > select the test.bat file, under *Start in(optional) : enter the directory where the test.bat is (note: this is optional but on some systems the file doesn't run without this part)
    • the rest of the settings can be left as is, so press ok.

    4 - On the Actions panel on the right, there is a 'Enable All Tasks History' enable it, to see task results / errors in the History tab.

    5 - Lastly : You can also select and run the task manually.