Running Node.Js on Android

Androidnode.jsCordovaAndroid NdkJxcore

Android Problem Overview


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

  1. https://stackoverflow.com/questions/31111377/run-nodejs-server-in-android
  2. https://stackoverflow.com/questions/11392590/how-to-run-my-node-js-project-on-android?lq=1
    and
  3. https://stackoverflow.com/questions/29145308/nodejs-on-ios-android?rq=1

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 https://stackoverflow.com/questions/36506305/cant-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.

Android Solutions


Solution 1 - Android

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.

Solution 2 - Android

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)

Solution 3 - Android

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.

Solution 4 - Android

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/

Solution 5 - Android

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.

Solution 6 - Android

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

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMariusRView Question on Stackoverflow
Solution 1 - AndroidPyroView Answer on Stackoverflow
Solution 2 - AndroidSaeed HeidarizareiView Answer on Stackoverflow
Solution 3 - AndroidAlexis CampaillaView Answer on Stackoverflow
Solution 4 - Androidpathik devaniView Answer on Stackoverflow
Solution 5 - AndroidDoz ParpView Answer on Stackoverflow
Solution 6 - AndroidW. B.View Answer on Stackoverflow