Installing and running nodejs in android

nodejs android tutorial kickwe

What is this tutorial about ? 

In this tutorial we will install and  run nodejs in our android phone. There are bunch of tutorial over internet about nodejs installation in windows or Linux but here we are going to do everything using our phone , installing and running nodejs in android!

So Installing and running nodejs in android!

What we will achieve?

Installing and running nodejs in android

 

At first download termux from google playstore which is free to use . You can search it in google playstore or download it from above link ( at Application). It requires android 5.0+ version running in your phone. So for now lollipop, marshmallow and nougat users can use it. And initially it doesn’t require root access.
Now open termux , it will show you a welcome screen. Press OK.

Installing and running nodejs in android

Now you will have a command line interface where you will be able to write your commands.
To install nodejs we need to setup some initial staffs first.

First command to write :

apt update && apt upgrade

android apt update && apt upgrade

android apt update && apt upgrade

and press enter in our keyboard. This doesn’t update the software or apt version but download lists of all available repository.

Then write :

apt install coreutils

apt install coreutils

apt install coreutils

And press enter, it will download core utilities to support some esstential commands like : dir ( to get list of all files and folder) or CD to enter a directory and many more.

Great, Now we will need a text editor which you can install using command in termux.

So write :

apt install nano

Great you have installed a text editor named nano by just writing 3 words!

Now let’s make a file using the terminal.

Write :

touch app.js

This will create a file. Ok where ? To see where is the file actually created , you can open a file explorer and go to root of the storage. Then <b>data/data/com.termux/files/home</b>. But in this case you will need root access, if you dont have root access , its OK to forget it .

So we have already created a file, lets open it and edit it .
To perform that, write :

nano app.js

So now you will see a new window appeared where you see nothing! So we are going to write something there like :
console.log(‘hurrah we are running on Android’);

You will need an advance keyboard , cause you will need CTRL to save or exit the text. So make sure you have already downloaded hacker keyboard and using that .

So press CTRL+X on your keyboard. This will ask you about your decision either save or no.

Write “y/yes” and press enter.  Ok file is saved so now lets move from this editor.

You will find yourself at the first window where you started all this.

At this moment we are ready to install nodejs and this is pretty easy. Write :

apt install nodejs

it will ask you to press y/n , press y and enter so it will get permission to install nodejs

Now additionally we can install express to have good package manager.

Write :

npm init

And press enter. Now you will get some options to write information about your project. You can leave them blank by pressing enter aswell. Finally npm is initilized.

Now write :

npm install express --save

And press enter.

And finally write :

node app.js

And press enter. This is the app.js that we created before, remember?

It should show you “hurrah we are running on Android” cause we wrote this before right?

But lets make something really useful !

write :

nano app.js

This will bring you back to the editor and delete the text you wrote before and  write/paste this below code:

var express = require('express'),
app = express(),
port = Number(process.env.PORT || 8080);
app.get('/', function(req, res) {
res.send('Welcome to kickwe Tutorial');
});
app.listen(port, function() {
console.log('Listening on port ' + port);
});

Press CTRL+X to save and press enter. Then press CTRL+C to exit .

Now again write :

node app.js

and you will see it shows “Listening on port 8080”

DONE!

Open your browser , write http://localhost:8080 and press enter !

and you will see :

Installing and running nodejs in android

Nodejs installed in android

Now you can get back to your terminal , open nano and edit your code and play with it.

So in a nutshell once again with all commands:

apt update && apt upgrade

 

apt install coreutils

apt install nano

touch app.js

nano app.js

apt install nodejs

node app.js

npm init

npm install express save

nano app.js

node app.js

At next tutorial we will cover how to clone a nodejs project from github and install and run it in our android. And of course only using your phone, android phone!

Post A Reply

Get KickWe Tutorial on Google PlayX