React: Use Axios To Post State To Mongodb
I am trying to post the states as data to MongoDB through Express and Node with Axios. class App extends React.Component { constructor(props){ super(props) this.state={
Solution 1:
To access the req.body
we need to use body-parser middleware which Parse incoming request bodies in a middleware before your handlers.
Installation
$ npm install body-parser
>
var app = require('express')();
var bodyParser = require('body-parser');
app.use(bodyParser.json()); // for parsing application/json
Solution 2:
Please use app.post
in the server, currently you are creating a get endpoint you should first make a post endpoint to make a post request.
Please also check https://expressjs.com/en/guide/routing.html
Post a Comment for "React: Use Axios To Post State To Mongodb"