I'm building a react app with node.js (express && multer) and mongodb. When i upload a pic - the file is stored in a folder and the object is created in mongodb, but i get a 200 status instead of 201. What should i add to get the correct status?
fetch("http://localhost:8080/addItems", {
method: "POST",
body: data,
})
.then(res => res.status !== 201 ? setFileExistsError(true) : setFileExistsError(false))
};
return(
<>
{fileExistsError && <p className="errorMsg">Item already exists</p>}
</>
)
I have tried a post request with 201 status code on my node.js - react code and it worked. Your node.js code, should tell your react code that the status is "201".
data, and extra curly brace underthenin your code. You should clean them as well):