107

So I know this has been questioned quite a lot. To be exact for example in these questions:

  1. Run NodeJs server in Android
  2. How to run my node.js project on android?
    and
  3. NodeJS on IOS/Android

Every option presented has a problem though:

  • I want to run it on my normal device so I would like to avoid installing another OS on my Device

  • Work on JXCore was stopped last month and (maybe as a result) I couldn't get it to compile (see Can't install jxcore-cordova)

  • The Android Port of NodeJs Anode has not been worked on since 2014 and wasn't really maintained back then anyways
  • The second answer in the second thread I linked to mentioned there is an official node distribution for Android now but apart from a link to the Browse-Website of the latest dist I couldn't find any info on how to actually use it
  • I also saw this but it seems like the device has to be connected to a PC (or similar) to run the adb shell commands while I would like to make it as a separate App

With the time that past since these questions have been posted and as the "best option" JXCore seem to be now unusable:
Is there a way to run a node.js application (a server in my case) on an Android device?

if you're wondering why I'd want this: I made a WebApp with a Node.Js server and I now want a version you can launch locally from your phone without requiring an Internet connection. This means the server needs to run on an Android phone.

Arnold Schrijver
  • 2,610
  • 1
  • 23
  • 54
MariusR
  • 1,334
  • 2
  • 10
  • 15
  • 1
    Just out of interest, do you care if anyone else can actually use this app or are you just trying to make it so you can use it on your phone. Cause I can see this taking a lot of setup on the users/clients end if it could even work. – zgc7009 Apr 14 '16 at 19:59
  • 1
    I'd totally agree that if i would just use it on my phone my current attempt would be way too complicated. This Node.JS Server though is a sort of small Game Web Application Server so everyone playing the game would have to have access to that server. – MariusR Apr 14 '16 at 20:16
  • You aren't going to be able to bundle a Node.JS server into an Android build and very few people are going to be technically inclined enough to install it to play a game. If it is just for you that is one thing, but if it is supposed to be scaled at all I don't see how this is going to work. There are plenty of apps, particularly games that require not only an internet connection, but a strong one. – zgc7009 Apr 14 '16 at 20:21
  • I know but this APP on Android is just for me. It won't go up on any APP Store or anything. I will also deploy the server to a public hosted Webspace. That's why I don't want to negate from using node.js. The will to make an offline Version was me thinking "what if I want to play it with my friends offline'. – MariusR Apr 14 '16 at 20:26
  • I get what you are saying. Honestly, if your goal is to be able to take a server with you, I would look into loading it into a virtual box on a laptop or something. Just not sure that Android is designed to handle stuff like this. – zgc7009 Apr 14 '16 at 20:31
  • If this would be for a big or important node.js application i would do that and my backup if all else fails was even to use my raspberry pi which i have just lying around currently. But because my goal was to have it in such a way that wherever you are you can just go "hey how a about we play a round of this game" and just open up the server without having to get a seperate laptop. I also see it more as an experiment to see what's possible. – MariusR Apr 15 '16 at 23:49
  • Why don't you just create the server in Java using the Android SDK? – Jonas Köritz Dec 20 '16 at 23:48
  • 2
    I thought about that as well but considering that my server heavily relies on the socket.io framework it made create the server in Java way more difficult. Also i already had quite a lot of the code in NodeJS down and i didn't feel like rewritting a large part of it. The solution using Termux works extremely well btw and i still use it for my purpose though i have to say i would never used it if my nodejs was an actual product i would sell as it's way too clunky for that. – MariusR Dec 24 '16 at 16:03
  • **Note**: Most information on this page is out-of-date. I investigated some recent options for running on android: [Viable options to running NodeJS on Android (Aug 2017)](https://stackoverflow.com/a/45649995/8295283) – Arnold Schrijver Aug 12 '17 at 15:13
  • @zgc7009 _Cause I can see this taking a lot of setup on the users/clients end if it could even work_ I don't know Android OS well enough yet, but isn't Android just a modified version of Linux? I can install many different run-time environments on Linux. Why this should be different/hard with Android Linux? – Green Jun 27 '18 at 22:26
  • node.js has enough issues being cross platform between Windows, Linux, and OS X due to the existence of packages which require compilation and target a specific OS. – Michael Nov 11 '18 at 19:16
  • Have you seen Dory https://play.google.com/store/apps/details?id=io.tempage.dorynode – Hassan Voyeau Apr 18 '20 at 00:23

6 Answers6

100

I just had a jaw-drop moment - Termux allows you to install NodeJS on an Android device!

It seems to work for a basic Websocket Speed Test I had on hand. The http served by it can be accessed both locally and on the network.

There is a medium post that explains the installation process

Basically: 1. Install termux 2. apt install nodejs 3. node it up!

One restriction I've run into - it seems the shared folders don't have the necessary permissions to install modules. It might just be a file permission thing. The private app storage works just fine.

Pyro
  • 1,229
  • 1
  • 9
  • 7
  • 5
    The weird thing is there was already an answer i accepted for this question that described the same thing you did but it seems like it got deleted for some reason. That's why i accepted your answer as i started using Termux back then and am still using it. – MariusR Jan 13 '17 at 07:52
  • 7
    Thanks. I was surprised by how much searching I had to do before running into a reference of Termux. This thread was one of the early results I ran into, so I though I'd add it here to give the next searcher a shortcut ;) – Pyro Jan 18 '17 at 01:30
  • It seems that is ok to delete the accepted answer with 11 upvotes on a protected question, probably because it was a "link only" answer, so probably this one will also be deleted at some point... – jcesarmobile Jan 30 '17 at 12:23
  • 2
    Do you know if it will allow the server to keep running in the background if you exit the Termux app? How about when you lock the android? Thanks. – wayofthefuture Feb 26 '17 at 20:32
  • If you 'quit' termux it closes. If you switch apps, it stays running and a notification will show. – Pyro Mar 02 '17 at 19:47
  • 6
    I had to make $ apt update $ apt upgrade before it finds nodejs I used it on HUAWEI Note 6 – M.Hefny Jul 16 '17 at 01:08
  • Haven't tried `apt` so far as the app told me to use `pkg install` instead which worked like a charm. Thanks for bringing this to my attention – Can Rau May 01 '19 at 02:39
  • Following the medium post I stuck with apt (not found). Found out I can use pkg instead, and that's it. – err May 13 '19 at 14:32
  • If you plan to use vim, then you might want a better keyboard for terminal commands, like Hacker's Keyboard – bitsand Sep 13 '19 at 15:59
19

Dory - node.js

Great New Application
No Need to root your Phone and You Can Run your js File From anywere.

  • node.js runtime(run ES2015/ES6, ES2016 javascript and node.js APIs in android)
  • API Documents and instant code run from doc
  • syntax highlighting code editor
  • npm supports
  • linux terminal(toybox 0.7.4). node.js REPL and npm command in shell (add '--no-bin-links' option if you execute npm in /sdcard)
  • StartOnBoot / LiveReload
  • native node.js binary and npm are included. no need to be online.

Update instruction to node js 8 (async await)

  1. Download node.js v8.3.0 arm zip file and unzip.

  2. copy 'node' to android's sdcard(/sdcard or /sdcard/path/to/...)

  3. open the shell(check it out in the app's menu)

  4. cd /data/user/0/io.tmpage.dorynode/files/bin (or, just type cd && cd .. && cd files/bin )

  5. rm node

  6. cp /sdcard/node .

  7. (chmod a+x node

(https://play.google.com/store/apps/details?id=io.tempage.dorynode&hl=en)

Saeed Heidarizarei
  • 6,314
  • 15
  • 47
  • 88
  • 2
    seems to have some issues running npm install, complained about no access to "/" and read-only access to the FS, for instance. – Michael Jan 06 '18 at 18:33
  • Contact them: (tempage.io@gmail.com) – Saeed Heidarizarei Oct 08 '18 at 10:12
  • Seems to only support a very old version of Node. About 6.x while current as I post this is 10.x/11.x – hippietrail Mar 17 '19 at 12:31
  • updating is much easier now:
    upgrade node.js : 'download file' menu -> check 'appfiles' -> check 'executable'
    v6.12.3 arm : https://dorynode.firebaseapp.com/v6.12.3_arm_release/node
    v8.3.0 arm : https://dorynode.firebaseapp.com/v8.3.0_arm_release/node
    v8.9.4 arm(only for android 5.0 above) : https://dorynode.firebaseapp.com/v8.9.4_arm_release/node
    v10.15.1 arm(only for android 5.0 above) : https://dorynode.firebaseapp.com/v10.15.1_arm_release/node see https://myket.ir/app/io.tempage.dorynode?lang=en
    
    – Kay Marquardt Jan 26 '20 at 09:50
  • Running the average Node app on your phone seems like a great way to fill up its internal storage :) But say I have a small server app that doesn't require a ./node_modules dir and runs from ./dist via `nps serve dist`. Will that run (in theory) and if so how do I get it onto the phone in the proper location? – RJVB Nov 03 '20 at 19:23
16

You can use Node.js for Mobile Apps.

It works on Android devices and simulators, with pre-built binaries for armeabi-v7a, x86, arm64-v8a, x86_64. It also works on iOS, though that's outside the scope of this question.

Like JXcore, it is used to host a Node.js engine in the same process as the app, in a dedicated thread. Unlike JXcore, it is basically pure Node.js, built as a library, with a few portability fixes to run on Android. This means that it's much easier to keep the project up to date with mainline Node.js.

Plugins for Cordova and React Native are also available. The plugins provide a communication layer between the JavaScript side of those frameworks and the Node.js side. They also simplify development by taking care of a few things automatically, like packaging modules and cross-compiling native modules at build time.

Full disclosure: I work for the company that develops Node.js for Mobile Apps.

  • Thanks, works great! Fully satisfied my needs with `npm` and multiple file support (ended up not using, but it's good to know it's available). Almost managed to make `canvas` work, but I would need to take some extra steps in Linux (currently using Windows) and I found a replacement library that doesn't require it. – GuiRitter Aug 08 '18 at 14:18
  • Hiya, Alexis. Will this run express? – mahesh Jul 16 '19 at 11:05
  • Hi @mahesh, you can definitely use express. Running an http server and p2p communications (e.g. with websockets) are very common scenarios for using nodejs-mobile. In case you want to use Cordova, you might find this sample app useful as it uses express: https://github.com/JaneaSystems/nodejs-mobile-samples/blob/651937e419bf1c82fda1f06e8f9c828d5df86fbc/cordova-angularjs/src/server/main.js#L13 – Alexis Campailla Jul 19 '19 at 15:14
11

J2V8 is best solution of your problem. It's run Nodejs application on jvm(java and android).

J2V8 is Java Bindings for V8, But Node.js integration is available in J2V8 (version 4.4.0)

Github : https://github.com/eclipsesource/J2V8

Example : http://eclipsesource.com/blogs/2016/07/20/running-node-js-on-the-jvm/

pathik devani
  • 512
  • 5
  • 13
2

the tutorial of how to build NodeJS for Android https://github.com/dna2github/dna2oslab/tree/master/android/build
there are several versions v0.12, v4, v6, v7

It is easy to run compiled binary on Android; for example run compiled Nginx: https://github.com/dna2github/dna2mtgol/tree/master/fileShare

You just need to modify code to replace Nginx to NodeJS; it is better if using Android Service to run node js server on the backend.

Arnold Schrijver
  • 2,610
  • 1
  • 23
  • 54
Doz Parp
  • 212
  • 3
  • 17
0

Node.js Frontend for Android

  • releases include signed apks
  • Android 4.4+
  • open source (GPLv2)
  • no root
  • frontend for Node.js for Mobile Apps by Janea Systems
    • which was announced earlier in this thread by one of its developers
    • which is a game-changer; great work!
  • at a high level:
    • the "exec in same process" tab:
      • includes a list of Node.js apps that are intended to run for a short period of time while the application remains open, and may only be executed one at a time
    • the "fork to separate process" tab:
      • includes a list of Node.js apps that are each executed in a separate foreground service in a distinct process, and are intended to hold long-running daemons (ex: various types of servers)

screenshots animation

W. B.
  • 33
  • 1
  • 5