title: Empty object returned from gRPC Server
body: <p>Basically, the JSON object that's returned from a callback in my gRPC server is empty no matter what I do. </p>
  
  <p>For the most part I'm following <a href="https://mherman.org/blog/node-grpc-postgres/" rel="nofollow noreferrer">this</a> tutorial, except I'm using a SQLite3 server instead of knex, and I've worked to the <em>listProducts</em> method. I haven't tried working on the other product methods yet. </p>
  
  <hr>
  
  <p>In <em>server.js</em> I get some data from a SQLite3 database, and try to return it in a callback (at the bottom of the method). I also print out the data from the DB to confirm I'm actually getting valid data. </p>
  
  <p><strong><em>gRPC server.js</em></strong></p>
  
  <pre><code>function listProducts(call, callback) {
    console.log("******** Listed the products *********");
    var data = "";
  
    let db = new sqlite3.Database('../data/testDB.db', sqlite3.OPEN_READONLY, (err) =&gt; {
      if(err){
      console.error(err.message);
      }
      console.log("connected to DB");
    });
  
    db.serialize(() =&gt; {
      db.get('SELECT NAME as name FROM PEEPS', (err, row) =&gt; {
            if(err){
              console.error(err.message);
            }
            console.log(row.name);
            data.name = row.name;
      });
    });
  
    db.close((err) =&gt; {
      if(err) {
        console.error(err.message);
      }
      console.log('closed db');
    });
  
    callback(null, { products:  data.name });
  }
  </code></pre>
  
  <p><strong>Out put from <em>gRPC server.js</em></strong></p>
  
  <pre><code>******** Listed the products *********
  connected to DB
  Jeff            // Correct data from DB. 
  closed db
  </code></pre>
  
  <hr>
  
  <p>The callback returns to <em>client.js</em>, where it was called. However, the object is always empty. </p>
  
  <p>If I uncomment <em>res.json({ name: "jessie" });</em> and comment <em>res.json(result);</em>, the code works as expected; <em>name: jessie</em> is sent to the browser as a JSON object. </p>
  
  <p>So that tells me that from the client to the browser the data is being handled correctly. Therefore the problem is when the data is passed from the <em>server.js</em> to <em>client.js</em>.</p>
  
  <p><strong><em>gRPC client.js</em></strong></p>
  
  <pre><code>// requirements
  const path = require('path');
  const protoLoader = require('@grpc/proto-loader');
  const grpc = require('grpc');
  
  // gRPC client
  const productProtoPath = path.join(__dirname, '..', '..', 'protos', 'product.proto');
  const productProtoDefinition = protoLoader.loadSync(productProtoPath);
  const productPackageDefinition = grpc.loadPackageDefinition(productProtoDefinition).product;
  const client = new productPackageDefinition.ProductService('localhost:50051', grpc.credentials.createInsecure());
  
  // handlers
  const listProducts = (req, res) =&gt; {
    client.listProducts({}, (err, result) =&gt; {
        console.log(result);
        console.log(typeof result);
        // console.log(res.json(result));
        res.json(result);
        // res.json({ name: "jessie" });
        console.log("*******************");
    });
  };
  </code></pre>
  
  <p><strong>Output from <em>gRPC client.js</em></strong></p>
  
  <pre><code>Server listing on port 3000
  {}                 //Oh no! An empty JSON object!
  object
  *******************
  </code></pre>
  
  <hr>
  
  <p><strong>Edit</strong>
  Here is a link to my repository: <a href="https://github.com/burke212/grpc-node" rel="nofollow noreferrer">https://github.com/burke212/grpc-node</a></p>