1

Maybe what I'm about to ask is stupid, generally I don't have so experience with server-side.

I'm building an Angular web application, with nodeJS on the server-side.

I need that the server (Node.exe) will installed in the device itself (IOS/Android), and nodeJS will open a localhost socket to communicate with the device.

(According to nodeJS official web site, nodeJS only support windows/Mac OS/Linux)

It's possible to do that?

If not, there is another server can I install in the device?

cheziHoyzer
  • 4,803
  • 12
  • 54
  • 81

4 Answers4

1

Yes you can with JXCore (a fork of nodejs), more info in this link Build Mobile Apps with JavaScript and the Node.js Ecosystem repository is in here.

And how to compile it is in here JXCore - How to Compile

But if you need it to be nodejs (not the last version) you can use this link to do what you need Building and running Node.js for Android


UPDATED 27-09-2018

Like someone has pointed out, that project is no longer maintained but I have found and alternative by Using Termux on an Android phone you can use nodejs / gcc / vim / etc and more tools to do many thing

This link show how to do it for nodejs ( and I have tested it on my phone ): Building a Node.js application on Android - Part 1: Termux, Vim and Node.js

First install termux from playstore, of course.

Arnold Schrijver
  • 3,588
  • 3
  • 36
  • 65
senteix2
  • 11
  • 2
  • JXCore is unfortunately no longer maintained. I just asked a question on some alternatives that are currently (Aug 2017) viable: [Compiling NodeJS as native library on Android](https://stackoverflow.com/q/45459909/8295283) – Arnold Schrijver Aug 02 '17 at 14:56
  • @ArnoldSchrijver i've edited my answer by adding an alternative by using Termux, hope it helps you – senteix2 Sep 27 '18 at 15:58
  • Thank you @senteix2 but the requirement for Termux makes it unsuitable for non-technical users, plus you have to root your phone to work with Termux (last I checked). – Arnold Schrijver Sep 29 '18 at 08:25
  • @ArnoldSchrijver, I have an unrooted Moto Z , and termux with nodejs works perfectly there, but yes is for more technical users, beside that is an open source project and can be cuztomized/perzonalized and forked to comply for your needs, – senteix2 Sep 30 '18 at 15:36
0

I don't understand the point of using a server tool on the client side.

If your application should work with an offline mode, you should put all data and other in your client app (using cordova).

If your application works with an online mode the server side is needed to serve your data. Here you can setup a nodeJS API which provides routes for your application to have content to print.

I'm not sure I brought you the wanted answer, so can explain more the point of using a server tool on a client device?

0

What you are trying to achieve, turns your device into a server.

A server side language is meant to stay on the server. I don't really see why you need to open a localhost socket on the device to communicate with itself. Is it for offline testing? You can do that since you have a computer and a device, and both are connected to the same network. I believe a really good start would be understanding the concept of the Client-Server architecture first.

But in short, the proper way of implementing a Client-Server app using your chosen technologies would be: A server should provide the client with answers to his requests. So in Node.js (server-side), write whatever you want to communicate with your database (Create, Read, Update, Delete), do custom processing, etc... and return a structured answer.

The client is expecting answers to his requests, and is supposed to handle the answers in code. So the program written in AngularJS (which is your client-side language) will be installed on devices.

The client has to know the format of the server's answer. Is it plain text? XML? JSON? ...

mysticalnetcore
  • 181
  • 1
  • 11
0

so you mean you would like to have an app can run some services via http?

not sure if iOS allows application with JS virtual machine executing code ...

and for Android
searching on Github and I find how to build NodeJS for Android https://github.com/dna2github/dna2oslab/tree/master/android/build

Here is an example to run compiled Nginx binary on Android at https://github.com/dna2github/dna2mtgol/tree/master/fileShare

You may modify a little more to replace Nginx to NodeJS. The code to run Nginx is not very nice; maybe you can try an Android Service to let the server run on backend on Android device.

Hope it is what you want.

Doz Parp
  • 279
  • 4
  • 23