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

252
Views
Database connection in Browser with JS

I'm currently writing a frontend plugin for Grafana with typescript react. For testing purposes I want to connect to a mysql database, which is locally hosted on my maschine with xampp.

This is my code for the connection:

var mysql = require('mysql');

var con = mysql.createConnection({
  host: "localhost",
  user: "myusername",
  password: "mypassword"
  database: "plugin-test"
});

con.connect(function(err) {
  if (err) throw err;
  console.log("Connected!");
});

If start the plugin (with yarn watch) and open the console in Browser I get:

Uncaught TypeError: Net.createConnection is not a function

After some research I discovered that this error is because JS in Browser is working different from JS with node.js.

I know this is intentionally because of security issues and not exposing the database, but as mentioned before this is just for testing purposes.

It would be very good, if someone know how to get some sort of workaround for this.

Another thing I read was that it is possible, to make two parts and connect them with a (Rest?) API. But I dont know much about how to code such API. If anyone has some tips on that it would be very nice.

I hope someone can help me with this.

Thank you in advance.

With kind regards
Tobias

about 4 years ago · Juan Pablo Isaza
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!