Reputation: 1
const pythonProcess = spawn('python',["tiqi.py", "textFile.txt"]);
pythonProcess.stdout.on('data',(data)=>{
console.log(data.toString());
})
Can I call and run that code by clicking a component button in my react project?
Upvotes: 0
Views: 1439
Reputation: 187
Short answer: No. But other Node-based functions can be invoked using Browserify.
Refer to this link: https://github.com/browserify/browserify/issues/1816
Upvotes: 1
Reputation: 518
You cannot use node
-based functions in a browser environment, to do such a thing in a proper way you should build an HTTP/HTTPS API for your react
application and make requests from react
to your API.
You can go through by googling building a simple node
server based on express
, and output your python
script results in maybe .json
file which you'll read with node
(which will be sent on request from your react
application).
Hope my answer will help you a bit.
Upvotes: 3