0
//server.js

app.post('/trip', function(req,res){
  var params = "something";
  getResult(params).then((db)=>{
    // I want to access variable named "db" in App.js(React), but I don't know how to do.
    res.send(db);
    res.end();
  });
});

I want to access variable named "db" in App.js(React), but I don't know how to do. If I use axios like

//App.js

axios.get('http://localhost:3000/trip').then((response)=>{
  console.log(response.data);
})

but "GET http://localhost:3000/trip 404 (Not Found)" prints. How can I solve this problem?

1 Answer 1

2

The /trip endpoint is of type post, you should be using axios.post() instead of axios.get().

axios.post('http://localhost:3000/trip',#POST Call Body#)
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    console.log(error);
  });

Refer https://axios-http.com/docs/post_example for more details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.