PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, October 14, 2022

[FIXED] How do I pass this data i get from axios to the backend which uses node.js (react & node.js)

 October 14, 2022     axios, node.js, reactjs     No comments   

Issue

This is the backend (node.js) route that i want to send the data to.

app.post('/saveDiseaseDetails' , (req , res) => {
  //Console.log the data here
})

This is the axios that returns some data and I want to send that data to the backend

axios.post("https://api.plant.id/v2/identify", data)
  .then(({ data }) => console.log("SUCCESS", data))}

Basically, what I want is to get the data from the axios request and console.log it in the backend. I am new to react and axios so I am having a little bit trouble


Solution

Frontend

const url_to_your_backend //this has to be added accordingly
axios.post("https://api.plant.id/v2/identify", data)
  .then(async({ data }) =>{
       console.log("SUCCESS", data)
       const backend_response=await axios.post(url_to_your_backend,data,{})
       console.log("backend response",backend_response)
   })

Backend

app.post('/saveDiseaseDetails' , (req , res) => {
  //Console.log the data here
  console.log(req.body)
  res.status(200).json({message:"received data in backend})
})


Answered By - Kaneki21
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing