title: Insert data into res.body back to client
body: <p>with my client js i have perform a fetch and send along some data.
  And i've attempted to do a res.send or res.json to send a result back.</p>
  
  <p>Do I need to create a new json and send it?</p>
  
  <p>Express Server</p>
  
  <pre><code>const express = require('express');
  const app = express();
  
  const pg = require('pg');
  const conString = 'postgres://postgres:password@localhost/postgres';
  
  const bodyParser = require('body-parser');
  
  app.use(bodyParser.json()); //support json encoded bodies
  app.use(bodyParser.urlencoded({ extended: true})); //support encoded bodies
  
  app.use(function(req, res, next) {
    res.header("Access-Control-Allow-Origin", "*");
    res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
    next();
  });
  
  app.listen(3000, function () {
    console.log('Server listening on port 3000!');
  });
  
  app.post('/', function(req, res){
  
    var uname = req.body.username;
    var pw = req.body.password;
  
    QueryByUserName(uname, function(err, result){
      if(err){
        console.error('error happened', err);
        //handle error
      }
  
      if(uname == result.username){
        //name is in our database
        if(pw == result.password){
          console.log("User and Password Correct!");
          res.json({ message: 'correct' });
        } else {
          console.log("Password Incorrect!");
          res.json({ message: "incorrect" });
        }
      } else if(result.username == "undefined"){ //placeholder
        console.log("username does not exist");
        res.send( {message: "dne"} );
        console.log(res);
      }
  
    });
  });
  
  function QueryByUserName(input, callback) {
    pg.connect(conString, function(err, client, done){
      if(err){
        callback(err);
        return;
      }
  
      client.query(SelectAll(), function(err, result){
        //Query database for all usernames
        done();
  
        var isFound = false;
  
        for(var x = 0; x &lt; result.rows.length; x++){
          //loop through all usernames from database.
          if(result.rows[x].username == input){
            isFound = true;
            //username exists, now we obtain the rest of the data.
            client.query(findDataInDatabase(input, '*'), function(err, result){
              done();
  
              if(err){
                callback(err);
                return;
              }
  
              console.log(result.rows[0]);
              callback(null, result.rows[0]);
              //return all information regarding user to callback function
            });
          } else if(x == (result.rows.length - 1) &amp;&amp; !isFound){
            callback(null, {username: "undefined"}); //placeholder
            //Username does not exist in database
          }
        } //end of For Loop
  
      });
    });
  }
  
  function findDataInDatabase(username, WhatWeLookingFor) {
    return 'select ' + WhatWeLookingFor + ' from users where username = \'' + username + '\'';
  }
  </code></pre>
  
  <p>Express server side will try to send a message to the client.
  but when I do this i did a console.log(res) it shows that the body is { null, null, null}</p>
  
  <p>Client login Function</p>
  
  <pre><code>handleLogin: function(){
      let fetchData = {
        method: "post",
        headers: {
          'Accept': 'application/json',
          'Content-Type': 'application/json'
        },
  
        body: JSON.stringify({
          username: this.state.user,
          password: this.state.password,
          message: null
        })
      }
  
      var fromServer = fetch('http://localhost:3000/', fetchData)
      .then(function(response){
        if( !response.ok){
          throw Error (response.statusText);
        }
        console.log(response);
        console.log(response.message);
        console.log(response.body);
        console.log(response.body.text);
        return response.json();
      })
      .catch(error =&gt; console.log("there was an error --&gt; " + error));
    },
  </code></pre>
  
  <p>Edit : Screenshots below</p>
  
  <p><a href="https://i.stack.imgur.com/ysQxy.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ysQxy.png" alt="enter image description here"></a>
  <a href="https://i.stack.imgur.com/OTCb8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/OTCb8.png" alt="enter image description here"></a></p>