Z
Z
zaxar2282018-07-24 19:16:55
JavaScript
zaxar228, 2018-07-24 19:16:55

How to overwrite res.send(data) when resending a POST request?

After the first call to the POST request, data is written to res.send(), but after the second call, the data variable does not change, how to fix this?

const express = require('express');
const bodyParser = require('body-parser');
const MongoClient = require('mongodb').MongoClient;
const fs = require('fs');
const conf = {encoding: 'utf8'};
const app = express();

  app.post('/yo', urlencodedParser, (req, res) => {
    var red = {
       text: req.body.message
     }
       fs.readFile(red.text, 'utf8', (err, data) => {
          if (err) {
            throw err;
          } else {
            app.get('/yo', (req, res) => {
              res.send(data);
            });

          }
          console.log(data);

     });

     //post yo
  });

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question