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

229
Views
Client Javascript getting data from backend express server

I have built an Express Server like this:

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}!`),
);

My Goal is to call the /getDataFromDatabase in client javascript and then use that data. How would I go about that?

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

0

Try the following on client-side:

<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!