Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

253
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda