logic-unit logic-unit - 2 months ago 27
Node.js Question

Send large JSON string from NodeJS to Python

I need to send a large JSON file from Node to Python. I can create the child_process with spawn to call the Python file, but I can't work out how to send the data to it. I've tried using pipe, but I'm not understanding the documentation.

Code:

var dataset = JSON.stringify(doc.data);

// Call the python API
try {
var py = require('child_process').spawn('python3', ['api.py', analysis, input]);
} catch(error) {
console.log(error);
}

// Pipe the data to the Python module
py.stdin.pipe(fs.createWriteStream(dataset));
py.stdin.end();


Error:

Uncaught Error: ENAMETOOLONG: name too long, open [file data printed to console here]

Answer

Here is a pretty good guide on what you are trying to do!

Seems like you also should do py.stdin.write('json data');