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
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:
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
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
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.
Now visit your browser on port 3000 (localhost: 3000). If you visit the / route you will see your browser information:
If you visit the page /pagina the server will respond with an HTML file:
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.