• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

104
Views
Call Node.js Script from React component
   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?

almost 3 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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.

almost 3 years ago · Juan Pablo Isaza Report

0

Short answer: No. But other Node-based functions can be invoked using Browserify.

Refer to this link: https://github.com/browserify/browserify/issues/1816

almost 3 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error