How to call a Python function from Node.js and Vice versa?

As of Python you can refer to functions in nodejs and Vice versa from a function in nodejs to call the function in Python?
June 27th 19 at 14:59
2 answers
June 27th 19 at 15:01
Solution
And why out of each other call? Both a server-side language, both can work as web server. And make two micro service on Python and node, and let information with each other in a shoot.
So! Have fun. How to make a micro service? Well, just General knowledge and principles. Well can examples if you have them. - donnell_Frami commented on June 27th 19 at 15:04
: well, the server will not say, but for Python - aiohttp take a flask or hang the server on localhost, and using json request-response chase all he wants. Everything is in the standard tutorials. Unlike large applications, you just spinning a web server on some port of the original type 5577, accepts requests from another application. In Python requests can be sent via requests, urllib2, aiohttp-client... - Kasey.Cruickshank commented on June 27th 19 at 15:07
: But could a bit of explanation. That is, if I create an app which will be divided into several REST-Ful services, each for their own tasks, it will be a normal decision and it is prelamin? Can I in a loop constantly for days to poll a single URL, and polosaty data? Just for fun did a service in Python, the sharp customer, which in the cycle it pulls. And from time to time there are exceptions that you cannot connect with a server. Why is this happening? You need to remove some timeouts? - donnell_Frami commented on June 27th 19 at 15:10
: if there are exceptions then logisuite them. In Python there is a nice logging library. And stacktrace see what's wrong.
And Yes, it is normal to question one url. You with multiple locations and very very quickly they created. And you can still use long pooling technique or websockets. View examples of chats on aiohttp, tornado, or twisted/cyclone.io. - Kasey.Cruickshank commented on June 27th 19 at 15:13
: Thank you. With web sockets is familiar, I have some application running on SignalR. I think that is the solution to my problem. - donnell_Frami commented on June 27th 19 at 15:16
June 27th 19 at 15:03
const spawn = require('child_process').spawn;
const ls = spawn('ls', ['-lh', '/usr']);

ls.stdout.on('data', (data) => {
 console.log(`stdout: ${data}`);
});

ls.stderr.on('data', (data) => {
 console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
 console.log(`child process exited with code ${code}`);
});


read more
here

Find more questions by tags PythonNode.js