Setting Up a NodeJS Web Server On Your Android Phone or Tablet

I came across a really cool app recently, specifically on my Samsung Galaxy S9 Android device. The app is called Dory and it’s capable of installing a full-working NodeJS environment on your device.

In this article, I will detail how to get your very first NodeJS web server setup on your device and ultimately connect to a web page locally. It won’t take longer than 10 minutes, so just for the cool factor, it’s well worth the time spent.

Step 1

  1. Open the Google Play Store on your device and search for ‘Dory’, see Figure 1 so that you know what it looks like when you see it. Alternatively hit the following link – Dory – Node.JS
  2. Hit the install button and await the app to finish downloading and installing.
dory app
Figure 1. Dory NodeJS – Play Store Listing

Step 2

  1. Locate the app on your device and launch it.
  2. As the app launches you will see a notification at the bottom, informing you of both Node and NPM installing.
  3. After this, another notification will inform you that they have been installed.
  4. Next, the NodeJS server will boot automatically, you can see this in the notification center, see Figure 2.
nodejs running notification
Figure 2. NodeJS Running Notification

Step 3

Time to write some code and serve our first page!

  1. Find the + icon at the bottom right of the app and tap it.
  2. Then, tap the ‘Eval Script’ button.
  3. Delete out the console.log('hello world'); code.
  4. Add the following code block to the file –

CodeBlock

const http = require('http');

let app = http.createServer((req, res) => {  
    // Set a response type of plain text for the response
    res.writeHead(200, {'Content-Type': 'text/plain'});

    // Send back a response and end the connection
    res.end('NodeJS Server Online!');
});

// Start the server on port 3000
app.listen(3000, 'localhost');

Step 4

  1. Goto the top right settings menu and use the ‘save as’ feature, save it as server.js in your documents folder.
  2. Navigate back to the home panel and make sure that the widget for the file is present and secondly make sure the ‘Start’ button is greyed out, meaning its active.
  3. If not, you can hit the + button, add file, and open the file from your documents folder.
  4. Now you can open up the browser, and navigate to http://localhost:3000
  5. See Figure 3, an example of my Chrome browser loading up the NodeJS Server.

 

node js server online
Figure 5. NodeJS Server Online

Summary

This article shows you the basic instructions to get a NodeJS web server set up on your Android device. But, there are many other features this app offers too. The app comes fresh with NPM, has a file downloader and even has the ability to git clone! The app developers also have some other great applications ready for download as well, one of which is MongoDB, you can check them out here.

SHARE ON

The Author: Dan Englishby

Setting Up a NodeJS Web Server On Your Android Phone or Tablet

You May Also Like

Leave a Reply

Your email address will not be published.