How to Learn JavaScript and Run Node.js in Termux — Android Dev Guide 2026
- Introduction — Why Learn JavaScript in Termux?
- Setting Up Termux for JavaScript Development
- Installing Node.js in Termux — Step by Step
- Writing and Running Your First JavaScript Programs
- Using npm — Node Package Manager in Termux
- Building Real Projects with Node.js in Termux
- Common Errors and Fixes
- Pro Tips for JavaScript Development in Termux
- Node.js vs Python in Termux — Comparison
- FAQ
- Conclusion
// 01 — Introduction: Why Learn JavaScript and Node.js in Termux?
If you want to learn JavaScript and run Node.js in Termux on your Android phone, you've come to the right place. JavaScript is the most widely used programming language on the planet — it powers every website you visit, every web app you use, and with Node.js, it can even run server-side applications directly on your terminal. The best part? You don't need a laptop or PC to get started. With Termux and a few simple commands, your Android phone becomes a fully capable JavaScript development environment — no root required.
In this complete guide, we'll walk through everything: setting up Termux, installing Node.js, writing JavaScript programs from scratch, using npm (Node Package Manager), and even building small real-world projects — all from your phone. Whether you're a complete beginner who has never typed a line of code, or an intermediate developer who wants to code on the go, this tutorial has you covered.
JavaScript isn't just a web language anymore. Thanks to Node.js, you can write scripts that read and write files, make HTTP requests, build REST APIs, scrape websites, automate tasks, and interact with databases — all from your terminal. Learning this on Termux is one of the most efficient ways to build real programming skills because you're working in a genuine Linux environment, which means everything you learn here transfers directly to real server administration and professional development workflows.
At HYDRA TERMUX, created by Rixon Xavier, we believe powerful coding should be accessible to everyone — even those who only have an Android phone. This guide is written for exactly that audience. Every command is explained, every concept is broken down, and you'll finish this post with a working Node.js environment and real JavaScript programs running on your device.
By the end of this guide, you'll understand how JavaScript works in a terminal environment, how to manage packages with npm, and how to write scripts that actually do something useful. Let's get into it.
// 02 — Setting Up Termux for JavaScript Development
Before we install Node.js, we need to make sure Termux itself is properly configured and up to date. This is a critical step that many beginners skip — and then wonder why their installations fail or packages behave strangely. A clean, updated Termux environment is the foundation for everything else in this guide.
Where to Download Termux
First things first — make sure you're using the right version of Termux. The Google Play Store version is outdated and no longer maintained. You must download Termux from F-Droid (f-droid.org) or from the official GitHub releases page (github.com/termux/termux-app/releases). Using the Play Store version will cause package errors and broken installations.
Updating Your Package Repositories
Once Termux is installed and open, the very first thing you should always do is update your package lists and upgrade existing packages. This makes sure you have access to the latest software versions and that your system is consistent.
pkg update && pkg upgrade -y
This command does two things: pkg update fetches the latest package lists from Termux's repositories, and pkg upgrade -y upgrades all currently installed packages to their newest versions. The -y flag automatically answers "yes" to any prompts, so you don't have to type confirmations manually. This process may take a few minutes depending on your internet speed.
Grant Storage Permission (Optional but Recommended)
If you want to save your JavaScript files to your phone's internal storage where you can access them from a file manager, run this command and tap "Allow" when prompted.
termux-setup-storage
After granting permission, a folder called storage will appear in your Termux home directory. You can navigate to your Downloads folder using cd ~/storage/downloads, which is handy when you want to share JavaScript files between Termux and other apps.
Installing Essential Development Tools
Before we get to Node.js, let's install a couple of tools that every developer needs: git for version control and curl for making HTTP requests from the terminal. We'll use both later in this guide.
pkg install git curl -y
Git allows you to clone repositories from GitHub, manage your code history, and collaborate on projects. Curl lets you download files and make web requests directly from the command line. Both are essential for any serious JavaScript or Node.js development workflow.
Setting Up a Code Editor in Termux
While you can write JavaScript in any text editor, having a good terminal-based editor makes the experience much smoother. Two popular choices in Termux are nano (beginner-friendly) and vim (powerful but has a learning curve). Let's install nano since it's easier for beginners:
pkg install nano -y
With nano installed, you can create and edit JavaScript files directly in the terminal. To create a new file, type nano filename.js. To save and exit nano, press Ctrl+X, then Y, then Enter. That's all there is to it.
// 03 — Installing Node.js in Termux — Step by Step
Now for the main event — installing Node.js in Termux. Node.js is a JavaScript runtime environment that lets you execute JavaScript code outside of a browser. It's built on Chrome's V8 JavaScript engine and provides a rich set of built-in modules for file I/O, networking, and more. Installing it in Termux is straightforward because Termux's package manager supports it natively.
Installing Node.js with pkg
The easiest way to install Node.js in Termux is using the pkg package manager. This single command handles everything — downloading the package, installing its dependencies, and configuring your environment.
pkg install nodejs -y
This installs both node (the JavaScript runtime) and npm (the Node Package Manager) in one go. The installation may take a minute or two. When it completes, you'll be returned to the Termux prompt with no errors.
Verifying the Installation
After installation, always verify that Node.js and npm were installed correctly by checking their version numbers. This also confirms that the executables are in your PATH and ready to use.
node --version
npm --version
You should see output similar to this:
v22.x.x
10.x.x
The exact version numbers may differ depending on when you run the installation — Termux regularly updates its packages to the latest stable versions. As long as you see a version number and no error message, you're good to go.
The Node.js Interactive REPL
One of the most useful features of Node.js is its interactive REPL (Read-Eval-Print Loop). A REPL is like a live JavaScript playground where you type an expression, press Enter, and immediately see the result. It's perfect for testing small pieces of code quickly without creating a file.
To launch the Node.js REPL, simply type:
node
You'll see a > prompt appear. Now you can type JavaScript directly:
> console.log("Hello from Node.js in Termux!")
Hello from Node.js in Termux!
undefined
> 2 + 2
4
> "HYDRA TERMUX".toLowerCase()
'hydra termux'
> .exit
The REPL is an excellent learning tool. As you study JavaScript, use it to test expressions, try out methods, and experiment with syntax in real time. To exit the REPL, type .exit or press Ctrl+C twice.
// 04 — Writing and Running Your First JavaScript Programs
Now that Node.js is installed in Termux, let's start writing actual JavaScript programs. We'll begin with the classic "Hello World" and progressively build up to more interesting scripts. Learning JavaScript through Termux is especially effective because you're writing real programs, not toy browser examples — and you see results immediately in your terminal.
Creating Your First JavaScript File
Let's create a project folder to keep things organized, then write our first script:
mkdir ~/js-projects
cd ~/js-projects
nano hello.js
The mkdir command creates a new directory called js-projects in your home folder. cd navigates into it. Then nano hello.js opens the nano editor with a new file called hello.js. Type the following inside nano:
// My first JavaScript program in Termux
console.log("Hello, World!");
console.log("JavaScript is running on Android via Node.js!");
let name = "Termux Developer";
let year = 2026;
console.log(`Welcome, ${name}! This is your coding year: ${year}`);
Save the file with Ctrl+X → Y → Enter. Now run it:
node hello.js
Expected output:
Hello, World!
JavaScript is running on Android via Node.js!
Welcome, Termux Developer! This is your coding year: 2026
Congratulations — you've just run your first JavaScript program from your phone! Let's break down the code: console.log() is the standard way to print output in Node.js. The backtick syntax (`Hello ${variable}`) is called a template literal — it lets you embed variables directly inside strings.
Working with Variables, Functions, and Loops
Let's write a more substantial program that covers the core building blocks of JavaScript: variables, functions, and loops. Create a new file:
nano fundamentals.js
// Variables
let message = "Learning JavaScript in Termux";
const MAX_ITEMS = 5;
// Function
function greet(name) {
return `Hello, ${name}! Keep coding.`;
}
console.log(greet("Android Dev"));
// Loop
console.log("\nCounting to", MAX_ITEMS);
for (let i = 1; i <= MAX_ITEMS; i++) {
console.log(`Step ${i}: Progress!`);
}
// Array and map
let tools = ["Node.js", "npm", "git", "curl", "nano"];
console.log("\nTools installed:");
tools.forEach(tool => console.log(" ✓ " + tool));
node fundamentals.js
This script demonstrates let and const for declaring variables, a reusable function with a parameter and return value, a for loop, and array iteration with forEach. These five concepts alone cover a huge portion of real-world JavaScript code.
Reading and Writing Files with Node.js
One of the key differences between browser JavaScript and Node.js is that Node.js can interact with your file system. This is one of the most powerful features you'll use in real projects. Here's how to read and write files using Node's built-in fs module:
// fileio.js
const fs = require('fs');
// Write a file
fs.writeFileSync('notes.txt', 'JavaScript is awesome!\nNode.js rocks in Termux.\n');
console.log("File written successfully.");
// Read the file back
const content = fs.readFileSync('notes.txt', 'utf8');
console.log("\nFile contents:");
console.log(content);
The require('fs') line loads Node.js's built-in file system module. writeFileSync creates a file and writes text to it. readFileSync reads it back as a string. The 'utf8' argument tells Node to decode the file as text rather than raw bytes. Run this with node fileio.js and you'll see your file created and read back in the terminal.
// 05 — Using npm — Node Package Manager in Termux
One of the biggest reasons Node.js is so powerful is npm — the Node Package Manager. npm gives you access to over two million open-source packages that other developers have written and published. Instead of reinventing the wheel, you can install a package and use it in your project with just one command. Learning to use npm in Termux is a critical skill for any JavaScript developer.
Initializing a Node.js Project
Before installing packages, you should initialize your project with a package.json file. This file tracks your project's name, version, and dependencies. It's how Node.js projects manage themselves.
mkdir ~/my-node-app
cd ~/my-node-app
npm init -y
The -y flag accepts all default values, so you don't have to answer a bunch of setup questions. After running this, a package.json file appears in your folder. You can view it with cat package.json.
Installing npm Packages
Let's install a popular and beginner-friendly package called chalk, which lets you add color to your terminal output. This is a great first package to learn with because the results are immediately visible.
npm install chalk@4
require() syntax we're using here.After installation, you'll notice a new node_modules folder in your project directory — this is where npm stores all downloaded packages. You'll also see chalk listed under dependencies in your package.json.
Now let's use chalk in a script:
// colorful.js
const chalk = require('chalk');
console.log(chalk.green('✅ Installation successful!'));
console.log(chalk.red('❌ This is an error message'));
console.log(chalk.yellow('⚠️ Warning: something to watch out for'));
console.log(chalk.blue.bold('ℹ️ Info: Node.js running in Termux'));
console.log(chalk.magenta('🚀 JavaScript is amazing on Android!'));
node colorful.js
You'll see colored output in your terminal — green for success, red for errors, yellow for warnings, and so on. Using colored output makes your programs much more readable and professional-looking.
Installing and Using axios for HTTP Requests
Another extremely useful npm package is axios, which makes HTTP requests simple. You can use it to fetch data from APIs — this is the foundation of how most web apps and automation scripts work.
npm install axios
// fetch-data.js
const axios = require('axios');
async function getJoke() {
try {
const response = await axios.get('https://official-joke-api.appspot.com/random_joke');
const joke = response.data;
console.log("\n📢 Random Joke from the Internet:");
console.log(`Setup: ${joke.setup}`);
console.log(`Punchline: ${joke.punchline}\n`);
} catch (error) {
console.error("Error fetching joke:", error.message);
}
}
getJoke();
This script makes a real HTTP GET request to a public joke API and prints the result. It uses async/await — modern JavaScript syntax for handling asynchronous operations (things that take time, like network requests). The try/catch block handles errors gracefully. Run it with node fetch-data.js and watch it fetch live data from the internet directly from your Termux terminal.
Key npm Commands to Remember
Here are the most important npm commands you'll use regularly as a JavaScript developer in Termux:
# Install a package
npm install package-name
# Install a package as dev dependency
npm install package-name --save-dev
# Uninstall a package
npm uninstall package-name
# List installed packages
npm list
# Update all packages
npm update
# Run a script defined in package.json
npm run script-name
# Install all dependencies from package.json
npm install
# Search for packages
npm search keyword
// 06 — Building Real Projects with Node.js in Termux
Now that you know the basics of JavaScript and npm, let's put it all together by building two practical, real-world mini-projects in Termux. These projects will teach you how to think like a developer, not just write syntax. Both run entirely on your Android phone — no server, no cloud, no PC required.
Project 1 — Command-Line To-Do List App
We'll build a simple to-do list that saves tasks to a JSON file. This project teaches you file I/O, JSON handling, command-line arguments, and basic application logic.
mkdir ~/todo-app
cd ~/todo-app
nano todo.js
// todo.js — Simple CLI To-Do App
const fs = require('fs');
const FILE = 'tasks.json';
function loadTasks() {
if (!fs.existsSync(FILE)) return [];
return JSON.parse(fs.readFileSync(FILE, 'utf8'));
}
function saveTasks(tasks) {
fs.writeFileSync(FILE, JSON.stringify(tasks, null, 2));
}
const args = process.argv.slice(2);
const command = args[0];
const text = args.slice(1).join(' ');
let tasks = loadTasks();
if (command === 'add') {
tasks.push({ id: Date.now(), task: text, done: false });
saveTasks(tasks);
console.log(`✅ Added: "${text}"`);
} else if (command === 'list') {
if (tasks.length === 0) {
console.log("📋 No tasks yet. Use: node todo.js add Your task here");
} else {
console.log("\n📋 Your Tasks:");
tasks.forEach((t, i) => {
const status = t.done ? '✓' : '○';
console.log(` ${status} [${i + 1}] ${t.task}`);
});
}
} else if (command === 'done') {
const index = parseInt(text) - 1;
if (tasks[index]) {
tasks[index].done = true;
saveTasks(tasks);
console.log(`🎉 Marked as done: "${tasks[index].task}"`);
} else {
console.log("Task not found.");
}
} else if (command === 'clear') {
saveTasks([]);
console.log("🗑️ All tasks cleared.");
} else {
console.log("Usage:");
console.log(" node todo.js add Buy groceries");
console.log(" node todo.js list");
console.log(" node todo.js done 1");
console.log(" node todo.js clear");
}
Now test your app:
node todo.js add Learn JavaScript in Termux
node todo.js add Build a Node.js project
node todo.js add Master npm packages
node todo.js list
node todo.js done 1
node todo.js list
This is a fully functional command-line application. It reads your tasks from a JSON file, modifies them, and saves them back. process.argv is how Node.js reads command-line arguments — process.argv[0] is node itself, [1] is the script name, and [2] onwards are your actual arguments.
Project 2 — Simple HTTP Web Server
Node.js is famous for its ability to run web servers. Let's build one from scratch using only Node's built-in http module — no external packages needed.
mkdir ~/node-server
cd ~/node-server
nano server.js
// server.js — Basic HTTP Server
const http = require('http');
const PORT = 8080;
const server = http.createServer((req, res) => {
res.writeHead(200, { 'Content-Type': 'text/html' });
if (req.url === '/') {
res.end(`
Hello from Node.js in Termux!
Your Android phone is running a web server.
Visit /about to learn more.
`);
} else if (req.url === '/about') {
res.end(`
About This Server
Built with Node.js, running in Termux on Android.
No root required. No laptop needed.
`);
} else {
res.writeHead(404);
res.end('404 - Page Not Found
');
}
});
server.listen(PORT, () => {
console.log(`🚀 Server running at http://localhost:${PORT}`);
console.log('Press Ctrl+C to stop.');
});
node server.js
Open your phone's browser and go to http://localhost:8080. You'll see your webpage served by your Node.js server running in Termux! This is how real web servers work — handling requests, checking URLs (routes), and returning HTML responses. Press Ctrl+C in Termux to stop the server.
// 07 — Common Errors and Fixes
Even experienced developers run into errors. Here are the most common problems you'll encounter when working with JavaScript and Node.js in Termux, along with exact solutions.
Error: "command not found: node"
Node.js isn't installed or isn't in your PATH. Run pkg install nodejs -y and then restart Termux. If it persists, run echo $PATH and verify /data/data/com.termux/files/usr/bin is listed.
Error: "Cannot find module 'xyz'"
You're trying to require a package that isn't installed. Run npm install xyz in the project directory. Make sure your terminal is in the same folder as your package.json.
Error: "ENOENT: no such file or directory"
The file path you're referencing doesn't exist. Check for typos in the filename. Use ls to list files in the current directory and confirm the file exists.
Error: "npm ERR! EACCES: permission denied"
This is a permission error when installing global packages. In Termux, always install packages locally (without -g) or configure npm's global directory: npm config set prefix ~/.npm-global, then add it to PATH.
Error: "SyntaxError: Unexpected token"
There's a syntax mistake in your JavaScript. Read the error message carefully — it tells you the line number. Common causes: missing closing bracket, missing semicolon (in some contexts), unclosed string, or a typo in a keyword.
npm install is extremely slow
This is usually a network or mirror issue. Try switching npm's registry: npm config set registry https://registry.npmjs.org/. Also make sure you have a stable Wi-Fi connection during installation.
// 08 — Pro Tips for JavaScript Development in Termux
npm install -g nodemon or locally) to automatically restart your Node.js app whenever you save a file. Use it with nodemon server.js instead of node server.js. This saves enormous time during development.node_modules folder to git. Create a .gitignore file with the single line node_modules/. Anyone who clones your project can run npm install to restore all dependencies from package.json.dotenv package (npm install dotenv) to load secrets from a .env file, and add .env to your .gitignore..map(), .filter(), and .reduce() interactively.termux-open filename.html to open files from Termux in your phone's installed apps. This lets you preview HTML files you create in your browser without a server.// 09 — Node.js vs Python in Termux — Which Should You Learn First?
Both Node.js and Python are excellent languages for Termux development. Here's a detailed comparison to help you understand the strengths of each and decide where to focus your energy.
| Feature | Node.js (JavaScript) | Python |
|---|---|---|
| Install Command | pkg install nodejs |
pkg install python |
| Primary Use Case | Web servers, APIs, front-end JS | Data science, automation, scripting |
| Package Manager | npm (2M+ packages) | pip (400K+ packages) |
| Beginner Friendliness | Moderate (async can confuse) | Very beginner friendly |
| Performance | Excellent (V8 engine) | Good (slower for CPU tasks) |
| Web Dev Relevance | Extremely high (full-stack) | Moderate (back-end only) |
| Cybersecurity Tools | Some (recon scripts, APIs) | Many (most security tools) |
| Community Size | Huge (largest on GitHub) | Very large |
| Job Market Demand | Very high (full-stack dev) | Very high (data science, AI) |
| Learning Curve | Moderate | Low to Moderate |
The honest answer: learn both. Start with whichever appeals to you more. If you're drawn to building web apps and APIs, start with Node.js. If you're more interested in automation, data, or cybersecurity scripting, start with Python. The logic and programming concepts transfer between languages easily, so your first language just needs to be one that keeps you motivated to practice.
// 10 — Frequently Asked Questions
pkg install nodejs on any unrooted device.npm install express and write your Express app as you normally would. You can build full REST APIs, serve web pages, and handle routes — all from your phone. The server will be accessible at localhost on your Android device and can even be accessed from other devices on the same Wi-Fi network.pkg update && pkg upgrade -y regularly to update all Termux packages including Node.js and npm. Termux keeps Node.js on a recent stable version. For npm specifically, you can also run npm install -g npm to update npm to the latest version independently.|, ~, and Tab without needing a physical keyboard.// 11 — Conclusion: Start Your JavaScript Journey Today
Learning JavaScript and running Node.js in Termux is one of the most rewarding things you can do with your Android phone. We've covered a lot of ground in this guide: setting up Termux for development, installing Node.js, writing your first programs, using npm to install packages, and building two real projects — a command-line to-do app and a working web server. All of this, running directly on your phone, no root required.
JavaScript is the world's most widely used programming language for good reason. It's versatile, it's powerful, and with Node.js, it's not limited to browsers — it can run anywhere from your Android phone to the biggest cloud servers on the planet. The skills you build here translate directly to real professional development work.
What makes this setup particularly special is that you're not using a sandbox or a simplified learning environment — you're working in a real Linux terminal, with the actual Node.js runtime, exactly as it runs in production. Everything you practice here counts.
The best projects from the hydratermux.blogspot.com community have started exactly like this — one terminal window, one curious person, and a willingness to type commands and see what happens. Rixon Xavier built this blog to lower the barrier between Android users and real programming education, and this guide is a perfect starting point.
Ready to go further? Check out our guide on building a full REST API with Express.js in Termux, and our tutorial on connecting Node.js to a database using SQLite — all no-root, all on Android. The path from curious beginner to confident developer starts with the commands you just ran. Keep going.

Comments
Post a Comment