Thursday, April 25, 2024
How ToProgrammingTech/WebTutorials/DIY

Node.js With Android

In this tutorial, I am telling to you how to use Node.js with Android Device (Include Smartphones). Node.js® is a JavaScript runtime built on Chrome’s V8 JavaScript engine.

How to use Node.js on Android

Android support is still experimental in Node.js, so precompiled binaries are not yet provided by Node.js developers.

However, there are some third-party solutions. For example, Termux community provides terminal emulator and Linux environment for Android, as well as own package manager and extensive collection of many precompiled applications. This command in Termux app will install the last available Node.js version:

pkg install nodejs

For LTS (Long Term Support) Version

pkg install nodejs-lts

Currently, Termux Node.js binaries are linked against system-icu (depending on libicu package).

Similarly You can use C, Python, Go etc programming language in Your Android Device easily.

What is Termux ?

Termux is an Android terminal emulator and Linux environment app that works directly with no rooting or setup required. A minimal base system is installed automatically – additional packages are available using the APT package manager. It combines powerful terminal emulation with an extensive Linux package collection.

• Enjoy the bash and zsh shells.
• Edit files with nano and vim.
• Access servers over ssh.
• Develop in C with clang, make and gdb.
• Use the python console as a pocket calculator.
• Check out projects with git and subversion.
• Run text-based games with frotz.

Read More about Termux – Termux Tutorials – Linux Environment Android app

Run HTTP server on Android Device using Node.js

Open Termux app

Install Node.js

Create a file “http.js” and paste given below code with vi editor.

var http = require('http');

http.createServer(function (req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('Hello World!');

If you don’t know, how to create file with vi editor. Follow following steps

Type on prompt

vi http.js

Now press i for insert text

Press ESC and type :wq for save and exit from text editor

Node Run this file

node http.js

Your http Server is running on your Android device.  Open any browser on your mobile and connected device in your local network. Insert this address http://localhost:8080

A Hello World message will be display on your screen.

I hope you like this post. Do you have any questions? Leave a comment down below!

Thanks for reading. If you like this post probably you might like my next ones, so please support me by subscribing my blog.

You may like also:

Harshvardhan Mishra

Hi, I'm Harshvardhan Mishra. Tech enthusiast and IT professional with a B.Tech in IT, PG Diploma in IoT from CDAC, and 6 years of industry experience. Founder of HVM Smart Solutions, blending technology for real-world solutions. As a passionate technical author, I simplify complex concepts for diverse audiences. Let's connect and explore the tech world together! If you want to help support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning! Linkedin

One thought on “Node.js With Android

Leave a Reply

Your email address will not be published. Required fields are marked *