How to Run a Node.js WhatsApp Bot on Android with Termux
You do not need a laptop or a paid server to test a Node.js bot. Termux gives you a Linux terminal on your Android phone, and it is enough to develop and run small bots.
Step 1: Install Termux
Install Termux from F-Droid. The version on the Play Store is outdated and package installs often fail.
Step 2: Install Node.js and Git
pkg update
pkg upgrade
pkg install nodejs git
Check the install with node -v and npm -v.
Step 3: Get your bot and install dependencies
git clone https://github.com/yourname/yourbot
cd yourbot
npm install
node index.js
Before running, you can check a file for syntax mistakes with node -c index.js. It catches typos without starting the bot.
Step 4: Keep it running
Android stops background apps to save battery, which will kill your bot. To reduce this:
- Run
termux-wake-lockto stop the phone from sleeping the session. - Turn off battery optimization for Termux in your phone settings.
- Use a process manager so the bot restarts if it crashes:
npm install -g pm2, thenpm2 start index.js.
Limitations
A phone is fine for development and light use, but it depends on your battery, signal and mobile data. For a bot that must be online around the clock, move it to a VPS or a hosting service once it has real users.