Save the data of a postgresql query in javascript?

1

I am using Nodejs, for the postgresql part I am using pg-promise. The query is performed with the following function, but I would like to save the data variable, which is the one with the values of the query, so I can use them later.

    function getUnUsuario2(req, res, next) {
  var pupID = req.body.usuario;
  db.any('select * from tienda.usuarioadmin where nombre_usuario= $1', pupID)
    .then(function (data) {
      localStorage.Usuariosa=data;
      if(data[0]==null){
       res.status(200)
        .json({
          status: 'No existe D:'
        }); 

  }

else { res.redirect (' link ');       }

}) .catch(function (err) { return next(err); });

}

    
asked by FrEqDe 01.12.2016 в 21:02
source

1 answer

3

The first thing you should be clear about is that localStorage / sessionStorage are only available in the browser (client). It should be he who is responsible for storing the data you need in the local Storage. The server can not access said storage.

There are some libraries that can help you, although I have not personally used them:      link

If you intend to store this data in the client's browser, you can send the data object in the response of the server and, once in the client, it is your frontend that stores that data in the localStorage.

    
answered by 01.12.2016 / 21:30
source