DELETE END POINT NOT WORKING

So my endPoint is not working when i press the button
1 Reply
anes039
anes039OP5mo ago
import express from 'express'; import cors from 'cors'; let storedData = []; const app = express(); const PORT = 3000; app.listen(PORT, () => console.log(Server is running on ${PORT})); app.use(cors()); app.use(express.json()) app.post('/edit', (req, res) => { const userData = req.body; console.log('received data', JSON.stringify(userData, )); storedData.push(userData); res.json({ message: 'data received successfully', data: userData }); }) app.get('/edit',(req,res) => { res.json({data:storedData}); }) app.delete('/edit', (req, res) => { const { id } = req.body; if (!id) { return res.status(400).json({ message: 'ID is required' }); } storedData = storedData.filter(data => data.id !== parseInt(id)); res.json({ data: storedData }); }); export default app; this is my server removeData: (state, action) => { state.studentData = state.studentData.filter( (data) => data.id !== action.payload ); fetch("http://localhost:3000/edit", { method:'DELETE', body:JSON.stringify(action.payload), headers: { "Content-type": "application/json; charset=UTF-8", }, }, ).then(response => response.json()).then(data => console.log(data)); localStorage.setItem( "profileData", JSON.stringify({ studentData: state.studentData }) ); }, and this piece of code is from my dataSlice.jsx
Want results from more Discord servers?
Add your server