Skip to main content

How to run a Node.js server on Android

If you are curious about node.js want to run on Android then, you arrived at the right place. In this blog, we are going to learn how to built node.js server using the express framework. As you know our smart android phones can do pretty much everything as we want if we know the way how to do it?

What we are going to do

  1. Installation and configuration
  2. Installing VIM code editor
  3. Installing and running Node.js
1. Termux

The Termux CLI
Termux combines terminal emulation with Linux package collection. It comes as a free app that can be installed directly from the play store.

2. Configuration
When you open Termux, you are greeted by a Command Line Interface (CLI). Right after installing Termux, it is recommended to check for updates and upgrade if need be. So type the following commands at the prompt — that is, after the ‘$’ sign — and press <Enter>:

$ apt update && apt upgrade

3. VIM
Vim is a text editor that can be used right in the Command Line Interface and it is available as a package in Termux. So let’s install it.

$ apt install vim

Vim’s interface is not based on menus or icons but on commands given in a text user interface. In case you are new to it, watch tutorials or use any other code editor.

3. VIM
Installing Node.js is very simple:

$ apt install nodejs

If you done this then, create a folder for the application, move into it and type:

$ npm init -y

Now let us check that everything is working all right. Open server.js

$ vim server.js

Paste the following code in server.js file

/* Simple Express.js Server */

const express = require('express')
const app = express()
const port = 3000

app.get('/', (req, res) => res.send('Hello World!'))

app.listen(port, () => console.log(`Example app listening on port ${port}!`))

And run it with following command

$ node server.js

This should print the text “Example app listening on port 3000” in the terminal.
Now open the web browser(Chrome) and visit localhost:3000. You will get a message "Hello World!"


Wrapping it up

We have seen how to use Termux on Android, how to edit files with Vim and how to run Node.js.

In the next blog, we going to learn how to use vim and setting it up.

Till then stay connected...



If this article is helpful, share it.


Comments