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
- 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
- Hit the install button and await the app to finish downloading and installing.
Figure 1. Dory NodeJS – Play Store Listing
Step 2
- Locate the app on your device and launch it.
- As the app launches you will see a notification at the bottom, informing you of both Node and NPM installing.
- After this, another notification will inform you that they have been installed.
- Next, the NodeJS server will boot automatically, you can see this in the notification center, see Figure 2.
Figure 2. NodeJS Running Notification
Step 3
Time to write some code and serve our first page!
- Find the + icon at the bottom right of the app and tap it.
- Then, tap the ‘Eval Script’ button.
- Delete out the
console.log('hello world');
code. - 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
- Goto the top right settings menu and use the ‘save as’ feature, save it as server.js in your documents folder.
- 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.
- If not, you can hit the + button, add file, and open the file from your documents folder.
- Now you can open up the browser, and navigate to http://localhost:3000
- See Figure 3, an example of my Chrome browser loading up the NodeJS Server.
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.
Cross Posted From : https://www.codewall.co.uk/
Top comments (1)
I was happy, that I could try NodeJS on Android. I opened playstore and tried to install Dory BUT i got the message that it can't run on my device. I have a Samsung Galaxy tablet S7 (SM T 870). Any hints. how to continue?