How to estabilish communication between an erlang application & a nodejs server? - node.js

I have an erlang app with API and i need to call these API functions from a nodejs server and process the response. For example: Nodejs sends data to app, app processes the data then sends it back to nodejs and finally nodejs processes the result.
So far my best idea was launching the app in a cmd as a child process but that is really hard to work with and when i looked up, all i found was people suggesting not to use nodejs but that is unfortunately not an option for me.
EDIT: For clarification my question is what is the best way to call the erlang functions from nodejs

Not sure I understand your request completely but for running the nodejs project on a server , I highly recommend using pm2. pm2 will manage your nodejs application. See http://pm2.keymetrics.io/
I don't know how large the data is you are sending, but if the data is large enough (i.e. processing it takes longer than 200ms) you might want to look into processing it asynchronously.

My suggestion is to implement Erlang application API as a RESTfull API using one of Erlang open source web servers Cowboy, Mochiweb, Webmachine. In this case you can invoke Erlang API from NodeJs using HTTP client (you can find a lot of implementation of HTTP client for Javascript and NodeJS especially). This way is easy for implementation and maintenance.
There is no easy way to invoke remotely Erlang functions from JavaScript. Erlang has ability to communicate with C/C++ (Erlang Port) and Java (JInterface) application only.

Related

Methods for calling APIs in one Nodejs app from another Nodejs app

Our application will have a website and a mobile app both communicating to the same API backend. I have one Nodejs application for serving only APIs and a second Nodejs app serving html pages for the website. I am using Expressjs web framework for both of these apps.
What are different methods to call APIs in one Nodejs from another Nodejs app? Additional information on when to use each method would be great.
EDIT:
Example,
I have the following applications
NodejsAPI (node & express)
NodejsWebsite (node & express)
MobileApp
NodejsAPI will provide access to APIs for the MobileApp and the NodejsWebsite. MobileApp will access APIs over http. But I want to know what are the options for NodejsWebsite to call APIs in NodejsAPI app. From what I understand this will be inter process communication between the two processes. For .net applications such communications could be done using .net pipes, tcp communication etc. What are the equivalent methods for Nodejs applications on unix and linux platforms?
Thinking from IPC perspective I found the following to be useful,
What's the most efficient node.js inter-process communication library/method?
https://www.npmjs.org/package/node-ipc
There's node's vanilla http client, http client swiss army knife, request, then there's superagent, similar to jQuery.ajax. To make your life easier there's armrest and fementa, both different flavors of the same thing.
Now if you want to reach for more performance and have another interface of your application, you can use one of these RPC solutions:
dnode: One of the most popular solutions. It's makes things very easy. It's makes using remote interfaces seamless. phantomjs-node uses dnode. Doesn't perform well with huge objects compared to others. For small stuff, it's perfect. There's other ports for other languages too.
zerorpc: Uses zeromq as it's socket library which is famous for being reliable. It supports connecting to a python client too.
smith: RPC systems used in cloud9 editor backend. Basically almost as nice as dnode, but faster. Both smith and zerorpc uses msgpack instead of JSON, so they will save bytes on the wire.
axon-rpc: A lightweight solution. As nice to use as zerorpc. You can configure it to use msgpack with axon-msgpack.
All of above work on both TCP(To be used on different machines) or Unix Domain Sockets(faster than TCP, but only on the same machine).
If you want more performance, you can embed your NodejsAPI in your NodejsWebsite, by just simply requiring it's interface module.
If you want answers better than this, write a more specific question. The question as it is, is too broad.

Qt Application - node.js server communication

I want to make a desktop application (since its supposed to be cross-platform, I've decided to stick with Qt, and I am already familiar with it) which connects to a server. The app is similar in concept to a chat application. I know that there are application servers, however as of now, I'm familiar with web server frameworks such as rails, and am trying out node.js currently.
I wanted to know how should I ask my application(Qt-based) to connect to the server, and the main question is, how should I implement the server? After thinking up of various options, including porting the whole project over to as a web-app, I've decided that the best bet would be to use the app to somehow connect to the node.js server and it will serve the html files which will contain the command for the app. Am I on the right path?
Can this (Qt-app & node.js server communication) be achieved in the way I am thinking? Is it the correct method?
It is easy to communicate with node.js app by socket. Using node.js to create a Net server (http://nodejs.org/api/net.html), and client use socket to connect to it. In my opinion it is easier to build a server with Node.js than C/C++ and has nice performance.
BTW, I think using node.js as server has gradually become a common solution. And My company have developed a mobile game with pomelo which is a node.js game framework.
For more infomation you can see this article http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js

How can I receive external program events in a node.js app and affect current Socket.IO connections?

I'm using a program (pianobar) that has the option to run a program when certain events happen. I want to get the information from these events into my node.js application so I can send it to clients that are connected over socket.io.
The best idea I've come up with so far is to have a middleware program that takes the input from pianobar and writes it to a file. I can then watch the file using fs.watchFile.
Is there a better/cleaner/more direct way to do this?
Depending upon how much data is involved, the cleanest solution is to follow tjameson's advice and POST the data to your node.js application. That way you can just use standard HTTP in your application and do not need to resort to using a one-off file approach. And you can use standard tools such as cURL to quickly and cleanly write the client program.

Decent Node.js library for server workload testing

I'm about to develop a web app so i tought i could test the workload with a single Node client since it can make multiple calls to the server without blocking.
Looking at https://github.com/joyent/node/wiki/modules, in the testing section i foun plenty of frameworks, and my question is if someone can recommend or has heard good things from any of those.
I think this is a perfectly answer question, that's why im asking it here.
Edit:
The idea is to use node on the client side not the server that serves the webapp, so profiling would be out of scope when it comes to decide what node testing framework to use.

Node.js and Socket.io - how far can they go with real time web applications?

I am going to build a web application to manage notes (think of something similar to Evernote). I have decided to use Backbone.js+JQuery client side.
Server-side, I haven't decided yet: either pure PHP (that I know very well) or Node.js+Socket.io (completely new to me).
I am considering Node.js+Socket.io because I would like to have my web application being real-time (i.e: if a user updates a note, that note gets updated instantly for a collaborator who shares that note, without reloading the page).
I was also considering, as a third alternative, to use Node.js and Socket.io for the UI and PHP for the REST API (I feel more comfortable to build an API with PHP). The PHP and Javascript code will share the MongoDB database.
My question is this: if I develop the REST API for my web application with PHP and a new note for the user gets created through the API (i.e.: the Android app sends an API request to create that note), will Node.js, Socket.it and Backbone.js be able to instantly update the UI of the user and show the new note on their screen? I think that can be called "push notification".
I hope I was clear enough.
Also, is there any alternative outstanding technology to build real time web applications?
Yes Node.js + Socket.IO will do a very good job of this. Node uses an event-loop, this means upon a request it is entered into a queue. Node deals with these requests one-by-one. Traditional web servers deal with a 'Thread-per-request' approach where a thread is created to handle that requests.
The benefit of Node here is that it doesn't need to context switch so often, this means it can deal with these requests very quickly... most likely faster than your PHP server. However Node runs as a single process, on a single CPU core. If your application is CPU intensive it could be that it blocks, meaning the time for each requests will be slower.
However it sounds to me like your application isn't CPU intensive, meaning Node.js will work well.
Decision
If your time is limited, and you don't want to learn a new skill (Node), PHP will be fine. If you have the time I recommend learning Node.js, as it is very strong when it comes to I/O intensive tasks such as a REST API for creating Notes.
Updating the UI
If your intended use is through a mobile device, I recommend using WebSockets but having a fallback such as long-polling. It is possible to update the Client UI using either Node or PHP. However from my experience it is much easier to do so using Socket.IO on Node.js.
Example Updating the client using Node.js / Socket.io
Client-side
socket.on('new-note', function (data) {
placeNewNote(data);
});
Server-side
socket.emit('new-note', data);
Getting Started With Node:
How do I get started with Node.js
Please also note, if you want to build a native Android mobile app which uses WebSockets... you will need to use: Java socket.io client
Using Node.js for both web server and push server is of course the best way. Especially since if you are going to use Node.js anyway then you have to learn it, so learning how to make a web server is only natural (I advice using the most famous Express framework).
Now you can use PHP for web server and Node.js for push server. To make them communicate with each other you would probably want to add Redis to your application. Redis will allow you to push notifications to any client connected to it, like PHP server or Node.js push server (and it scales well). From that point push server will push the data further to the client's browser.
Alternative technology would be for example Twisted server. Of course you'll need to learn Python in order to use it. And I don't know whether it supports WebSockets correctly. I think you should stick with Node.js + socket.io.

Resources