Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

312
Views
how to run this node.js when i click this button
/*socket.js*/
var net = require('net');

var ip = '127.0.0.1';
var port = 7000;

var socket = new net.Socket();
socket.connect({host:ip, port:port}, function() {
   console.log('connected');
   socket.write('1');
   socket.end();
});
/*home.js*/
function Home(){
    const emitOpen=(e)=>{
        e.preventdefault();
        /*i want to run that code*/
    }
    return (
        <div className="center">  
              <Button color="secondary" onClick={emitOpen}>blabla</Button>
        </div>
    );
  
}

i want to run socket.js to send imformation by tcp when i click the button on home.js.

home.js is base on react.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

your question is about how to implementation invoke/call a function(which trigger socket), so consider these steps:

  1. you need a button with an action
  2. your action will be calling an API
  3. this API can be GET or POST as they similar for this job
  4. implement your API endpoint on your node application
  5. connect your socket on this endpoint, so whenever the user presses the button, this endpoint will call and trigger to connect the socket connection.
  6. similarly you can create another API to close your socket connection.

hope to useful.

about 4 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 Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!