I need to get data (json) in my html page, with help of Ajax. I have a Nodejs server serving requests. I have to get the json from server, which is python code to process and produce json as output.
- So should i save json in db and access it? (seems complicated just for one single use)
- Should i run python server, to serve the requests with json as result (call it directy from html via ajax)
- Should i serve requests with nodejs alone, by calling python method from nodejs? if so how to call the python method. If calling python requires it to run server ? which one to prefer (zeropc, or some kind of web framework?)
Which is the best solution? or Which is preferred over other in what scenario and what factors?
Best How To :
As I understand:
You have a server running
- an app that acts as a webserver, made with nodejs.
- another app in python that does not expose an HTTP api, but you would like to interact with it in some way?
- You have control over the source code of both
When running big systems with parts programmed on different languages their are many ways to make it all work together.
The choice is yours, and you give us little information to help you decide which way is better. It all depends on how big are your python and nodejs apps, and what they do.
There are no magical way to call a python method from nodejs, or vice versa
Spawn persistent processes, and make them communicate with sockets, or pipes. Generally this is done with enabling libraries (like ZeroMQ + a serialization/RPC format).
Spawn persistent processes and make them communicate with a message queue in between (RabbitMQ, ActiveMQ, ...)
Spawn your nodejs webserver, and use the "child_process" module to spawn a process in python, and interact with it throught its standard input/output. There are helper libraries to do this: https://www.npmjs.com/package/python-shell
Just spawn the nodejs webserver and execute python scripts with "child_process" when you need them (no persistent python process).
Rewrite it all in python
Rewrite it all in nodejs