1

so i am creating a small application in Nodejs and Flask. I have created 2 apis. First one sending data from Nodejs App to Nodejs API then sending the data from the Nodejs API to flask api. I am having a bit of trouble sending the data from the Node Api to the Flask Api.

//send data from Node.js api to Flask Api

app.get('/postoflask',  (req, res) => {
 request('http://localhost:3030/users',  (error, response, bodyParser) => {
      if(error) {
          
          res.send(' erorr occured')
      }
  
      else {
          res.send(bodyParser)
          request.post('http://localhost:5000/adduser')
        }
  });
});

Deploying the route on the browser retrieves the data from the node Api database and pushes null values to the flask api database. i need the data retrieved from the Node Api to be transferred as it is to the database of the flask database.

port 3030/users is the node api that fetches data from database and port 5000/adduser is flask api to push data into database.

I am an entry to mid-level programmer, but i don't know what i am missing here or what i am not understanding. Help will be very appreciated. Database used is PostgreSql.

2 Answers 2

1

You can leverage request stream capabilities in order to proxy data from Node.js endpoint to Flask:

app.get('/postoflask', (req, res) => {
  request('http://localhost:3030/users')
    .on('error', (err) => {
      console.log(err);
    })
    .on('end', () => {
      res.send('done')
    })
    .pipe(request.post('http://localhost:5000/adduser'));
})
Sign up to request clarification or add additional context in comments.

1 Comment

This return 'done' and still sends null values to the database
0

You're not sending any data in request.post('http://localhost:5000/adduser'), try

request.post('http://localhost:5000/adduser',{...})

1 Comment

res.send(bodyParser) , bodyParser contains the data from the database, this line of code returns the data in json format on the browser, when passing it in request.post('localhost:5000/adduser',bodyParser) , still pushes null values into the flask api database

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.