How to install Node.js and NPM on Android using Termux app

In this post we will see how to install Node.Js and NPM (Node package manager) in Android.

At the end we will be able to run Node.js applications as if we had a Linux server.

We will also see how to install dependencies using the npm install command, since it is a possible thing in Android thanks to Termux.

Specifically we will install version 6.9.0 of NPM and version 12.3.1 of node, although perhaps when you read this post you will install a newer version.

Requirements

You need an Android phone with the Termux app installed on it. Look at this post to see how to install it.

We will see a simple example with Express to test a server with Node, which we saw in this post (in spanish).

You can see more Termux packages in this link.

Install Node and NPM on Android with Termux

Open your app and install the nodejs package, which will install node and npm. Execute:

pkg install nodejs

1 – Install node.js on Termux

If it asks you confirmation, choose Yes with the letter y and press Enter.

Wait for the installers and then check the npm and node version.

For npm execute:

npm -v

And for node execute:

node -v

As in the image:

2 – Check npm and node version installed on Android

So far you have correctly installed Node.js and NPM on Android. You can start developing and installing new dependencies or packages with npm install.

Now I will give you an example of an app to prove that the installation of node and NPM really works.

Test Node and NPM on Android with web app using Express

A few days ago I published how to start a simple project with Express and Node. I posted it on my GitHub so let’s clone it.

Start installing git with:

pkg install git

3 – Install Git on Termux

Clone the repository with:

git clone https://github.com/parzibyte/Node-Express-Plantilla-Base

After cloning it, enter to the dir with:

cd Node-Express-Template-Base

4 – Clone git repo

Note: you could have cloned it in another place, no matter the location because the dependencies will be installed in the directory where it is cloned.

When you are inside the directory, install the dependencies:

npm install

Run the server:

node index.js

If everything is ok, a message will appear showing the port number of the server.

5 – Install npm packages and start a server on Android with Termux

Now visit your browser on port 3000 (localhost: 3000). If you visit the / route you will see your browser information:

6 – Browse Node server on Android

If you visit the page /pagina the server will respond with an HTML file:

7 – HTML file served with Node and Express on Android using Termux

It was a simple example but this shows that we can access the entire Node ecosystem and the packages through NPM.

To stop the server simply press CTRL + C.


I am available for hiring if you need help! I can help you with your project or homework feel free to contact me.
If you liked the post, show your appreciation by sharing it, or making a donation

parzibyte

Freelancer programmer ready to work with you. Web, mobile and desktop applications. PHP, Java, Go, Python, JavaScript, Kotlin and more :) https://parzibyte.me/

Entradas recientes

Receipt designer for thermal printers – Free and open source

In the last months I have been working on a ticket designer to print on…

12 months hace

JavaScript: store and read files with the Origin Private File System

In this post you will learn how to use the Origin Private File System with…

1 year hace

JavaScript: download file with fetch

In this post you will learn how to download a file in the background using…

1 year hace

SQLite3 with vanilla JavaScript and OPFS – Hello world

In this post I will show you how to use SQLite3 directly in the web…

1 year hace

Python Thermal Printing: A Comprehensive Guide for Printing on Thermal Printers

In this tutorial, we'll explore how to effortlessly print receipts, invoices, and tickets on a…

1 year hace

Image printing on Thermal printer

When printing receipts on thermal printers (ESC POS) sometimes it is needed to print images…

1 year hace

Esta web usa cookies.