How to install Node.js in your Android device


Nodejs is a server-side JavaScript runtime environment. It was created by Ryan Dahl in 2009. And it is based on Chrome's V8 JavaScript engine. Node.js allows JavaScript to execute outside of the browser window. In this article, you will learn how to install Node.js in android device.

Installing Node.js in your Android device can make huge possibilities in your Android device. With Node.js, you can create a server. Install various packages in your project using Node Package Manager in short NPM. And it can do almost everything which you can do on a desktop.

Requirement

We need an application called Termux. Make sure to download Termux from GitHub or F-droid. Play store version may unsuccessful to install Node.js. We already have an article about Basic Termux and you can read that also.

Installing Node.js


Before installing Node.js, we need to update and upgrade our terminal by simply executing this command. It will update and upgrade the terminal at once.

apt-get update & apt-get upgrade -y


Next, install the Node.js using the pkg installer on Termux. Execute this command, and it will install Node.js in your entire Teamux system.

pkg install nodejs


Now, we need to check the version to ensure that the Node.js is installed or not; execute this command.
To check the node version, type

node -v


When you install Node.js, you also install NPM (Node Package Manager) automatically. To check which version is installed, just type

npm -v


If those command shows any version number like this (note: the version may not be the same as mine since those are version number)

~ $ node -v
v20.2.0
~ $ npm -v
9.6.6


Congratulation, you have successfully installed Node.js on your Android device.


How to run Node js


You can quickly run Node.js with its REPL. Type the 'node' keyword and hit enter, and a Node REPL will open on your Termux terminal. The 'node' keyword is also used to run any Node.js file on the terminal. In the node REPL, you can run Node.js directly. Here is an example:

~ $ node
Welcome to Node.js v20.2.0.
Type ".help" for more information.
> console.log("Hello World!");
Hello World!
undefined
>


In the above, first, I run the node command, which opens up its REPL. Then I write a basic console log javascript code and run it. You can see the result of the code Hello World! is printed successfully.

You can also run a Node.js file in the terminal. First, you will create and edit a file using the Vim editor. If you don't know about Vim then you can read this article.

vim myFirstNode.js


This command will temporarily create a file named myFirstNode.js and open it with the Vim editor. (You can use any editor available on your Termux)

Now go to insert mode by pressing the 'i' key. After that, write any JavaScript code. Save it by going to command mode and pressing the 'ESC' key. And write the command :wq and hit enter. It will save and quit from the editor.

console.log("Hello World!")


Inside the file, I write that code.

To run the file, type the node keyword and write the file name like this.
node myFirstNode.js

A successful run will show like this.

~ $ node myFirstNode.js
Hello World!


Congratulation, You have successfully run your first Node.js  code on Android mobile.

In conclusion, In this article, first, I showed how to install Node.js in Termux. Then, write a bit about node REPL and how to run a Node.js file on the terminal.

Istiak Ahmmed Soyeb

I'm Soyeb, Now I'm a web designer. I chose my career as a web developer. I'm also a Blogger (Not Professional). And I love technology very much.

Post a Comment

Previous Post Next Post