Saturday 29 June 2019

How to specify NodeJS 'child_process' dependencies / version?

I have a full stack web application with a React frontend and NodeJS backend. I'm using child_process to spawn a python process that calculates some values then returns those values to the JS parent process via print lines. This all works as expected.​The issue I'm having, or moreso my area of confusion, is where does the child_process script get it's PY source code from? I suspect that child_process is currently taking the PY version local to my machine somewhere in usr/bin (I'm on a Mac Air 10.13.2 if that matters)​I'd like to be able to specify the python version and have all dependencies/libraries installed inside of the server directory, so that I have them available to the PY process when the server is deployed- as opposed to the PY process just using whatever is on my machine.​I've looked into implementing some sort of pyenv but I'm confused as to how I can execute PY processes from my server application from Node in such a way that they refer to packages inside the server for source code and external libraries.​TLDR: How can I use child_process in such that it's child process refers to something like node_modules for dependencies.​// how I call the child_process spawn functionlet py = spawn( 'python', ['path_to_py_file', arguments])// normal handling of input/output

Submitted June 29, 2019 at 11:58AM by big_guzi

No comments:

Post a Comment