Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

254
Vistas
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
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda