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

180
Visualizações
add sql databas data array to localstorage

I have tried to add recordset of database to local storage to be used in browser.

I have tested to add the recordset to localstorage and return it back to the storednames array

//Connect to database
var sql = require("mssql");// appear undefined in browser 

var config = {
user: '****',
password: '****',
server: '****',
databse:'****',
port: 1433,
options: {
    trustedConnection: true,
    trustServerCertificate: true
  },
};

let test = [{field:"ddd"},{field:"AAA"}]; // appear undefined when called in browser 


sql.connect(config, function (err) {
    if (err) console.log(err);
    // create Request object
    var request = new sql.Request();
    // query to the database and get the records
    request.query("select * from Test ", function (err, recordset) {
        if (err) console.log(err)
        // write the records in console.log
        console.log(recordset) 
        //add recordset to localstorage then get array back from localstorage 
        localStorage.setItem("recordset", JSON.stringify(recordset));
        var storedNames = JSON.parse(localStorage.getItem("recordset"));
        console.log(storedNames);//it appears error 


    });
});

but when console.log the storedNames it appears an error in terminal..

Also another thing I did not understand. when I tried to open the browser, it shows in developer tool (require is undefined.. ) in server.js file, also tried to call (let Test) inside browser consule, always show undefined.

can any one please help me to understand what I am exactly missing.

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