'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.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source