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

227
Views
Cliente Javascript obteniendo datos del servidor backend express

He construido un servidor Express como este:

 var mysql = require('mysql2'); var express = require('express'); var app = express(); var PORT = 3000; app.get('/getDataFromDatabase', function(req, res) { console.log("Called") var con = mysql.createConnection({ host: "localhost", user: "root", password: "", // Password is filled () database: "casesdb" }); con.connect(function(err) { if (err) throw err; con.query("SELECT * FROM cases", function (err, result, fields) { if (err) throw err; res.status(200).send(result); console.log("Test") }); }); }); app.listen(PORT, () => console.log(`Example app listening on port ${PORT}!`), );

Mi objetivo es llamar a /getDataFromDatabase en el javascript del cliente y luego usar esos datos. ¿Cómo haría eso?

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

0

Pruebe lo siguiente en el lado del cliente:

 <script> fetch('http://localhost:3000/getDataFromDatabase') .then(response => response.json()) .then(data => console.log(data)) .catch(err => console.error(err)); </script>
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!