React App.js file
import './App.css';
import Form from './components/Form';
import Header from './components/Header';
import Fetch from './components/Fetch';
import { useEffect, useState } from 'react';
function App() {
const [count,setCount]=useState([]);
const handleAddProduct=()=>{
fetch('http://localhost:5000/p',{
method:"POST",
headers:{
'Content-Type':'application/json'
},
body:JSON.stringify({'name':'Rifat'})
})
}
return (
<>
<div>
<button onClick={handleAddProduct}>Click</button>
</div>
</>
);
}
export default App;
Nodejs app.js file
const express=require('express');
const app=express();
const PORT=process.env.PORT||5000;
const route=require('./paths');
const cors=require('cors');
const bodyParser=require('body-parser');
app.use(bodyParser.json());
app.use(cors());
app.post('/p',(req,res)=>{
console.log(req.body);
res.send('Thanks for calling me');
})
app.listen(PORT,()=>{
console.log("server is running at "+PORT)
});
Comments
Post a Comment