I’m trying to make a beginner application. My goal is to have a site where you can post things and they’ll be saved into the database, pretty basic.
Although, I’m getting pretty confused. So, I make a get request to display the react page on port 3000, but I’m also trying to make a POST request to my node backend on port 5000. How do I do this?
Sorry if this is vague, I’m just really confused lol.
That’s exactly what I did :(, including the proxy, it still says 404 because it’s searching port 3000 for /api/req (the express file) for some reason.
Here’s the express:
router.post('/api/req',(req,res)=>{
const newPost = new Post({
title: req.body.title,
description: req.body.description
})
newPost.save().then(()=>{
console.log('Item added to database!')
});
})
And here’s the axios request:
axios({
method: 'post',
url: '/api/req',
data: {
title: this.state.title
},
validateStatus: (status) => {
return true;
},
}).catch(error => {
console.log(error);
}).then(response => {
console.log(response);
});
I changed the url of the axious request to http://localhost:5000/routes/api/req and it gives me a 404(not found).
I also made the proxy to localhost:5000.