Title: sending data from one node js to another and displaying the sent data on the other node js
Tags: node.js;http;ejs
Question: i am trying to send data from one node js server to another and display the information sent. Example server A and server B. Server A sent data to server B and server B will display the information sent by server A and response with a answer back to server A. Basically my program is like a payment page and a bank-server page. Sending payment details to the bank-server and if the bank-server clicked accept, it will send back to the payment page and continue the transaction. 

This is my code for the payment page:

```var postData = JSON.stringify({ user: cardDetails });

    const options = {
        hostname: 'localhost',
        port: 3001,
        path: '/bank',
        method: 'POST',
        headers: {
            'content-type': 'application/json',
            'accept': 'application/json'
        }
    };

    const httpreq = http.request(options, (res) =&gt; {
        res.setEncoding('utf8');
        res.on('data', (chuck) =&gt; {
            console.log(`BODY: ${chuck}`);
        });
        res.on('end', () =&gt; {
            console.log('No more data in response.');
        });
    });

    httpreq.on('error', (e) =&gt; {
        console.error(`problem with request: ${e.message}`);
    })

    //write data to request body
    httpreq.write(postData);
    httpreq.end();
```

This is my code for the bank-server side:
App.js

```var express = require("express");
var path = require("path");
var bodyParser = require("body-parser");
var express = require('express');
var app = express();
var serverPort = 3000;
var httpServer = require('http').Server(app);

// ejs template path
app.set("views", path.join(__dirname, "server/views/pages"));
// view engine setup
app.set("view engine", "ejs");

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

//import order tracking
var bank = require('./server/controllers/bank');

app.get("/bank-server", bank.bankSystem);
app.post("/bank", bank.add);

console.log("Connected!")
app.listen(3001);
```

This is my bank.js code:

```exports.add = function (req, res){
    console.log(req.body.user.cardName);
    res.sendStatus(200);

};

exports.bankSystem = function (req, res){
    console.log("Bank Page Working!")
        res.render('bankServer', {
            name: "empty"
        })
    }
```

Lastly my bankServer.ejs code:

```<h1&gt;Connection Worked!</h1&gt;
<p&gt;Card Name is <%= name %&gt;</p&gt;
```

This is the output from payment node js. CardName entered = raysonkira1
This is the output from bankserver node js. received cardName



Here is another answer: you can use the rabitmq for data transfer or sencond solution is both side initialize the API your side you can post the data and bank side Get the data


Here is another answer: In Bank.js, you are just sending the status and not response.

```exports.add = function (req, res){
    console.log(req.body.user.cardName);
    res.sendStatus(200);
    // send the response data here, for example
    res.send("Hello from the bank!");
};
```

reference

Comment for this answer: `console.log(BODY: ${chuck});` is doing this right?
Comment for this answer: `res.on(` **`'data'`** `, (chuck) => {console.log(BODY: ${chuck});});`  will show response _data_ , status code is retrived via `res.statusCode` See first example in the http [documentation](https://nodejs.org/api/http.html#http_http_request_options_callback)
Comment for this answer: but how do i make the sent details appear in my ejs file?
Comment for this answer: Yup! It shows OK. Meaning the server responded using the res.sendstatus
Comment for this answer: Ah yea ik about that. But what can i do to make the details appear on my bankserver.ejs. since i got the info req.body.user in bank node js side.

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:07/06/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<node.js><http><ejs>', 'Title': 'sending data from one node js to another and displaying the sent data on the other node js', 'ViewCount': 1369, 'id': 51203680, 'user_AboutMe': None, 'user_AccountId': 12493916.0, 'user_DisplayName': 'Kira Izumi', 'user_Reputation': 17.0, 'user_Views': 13.0, 'user_id': 9094611.0}}