I'm creating a project with react and node, which consists of an app that adds people data to a database, in this project there is a basic front-end made with react, which is running on localhost:3000 and a back-end made with node that is running on localhost:3333.
The problem is that when I use axios in the font-end to interact (create, get or delete people from the database) with the back-end, at the click of a button, the following error appears:
Access to XMLHttpRequest at 'http://localhost:3333/person/' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
This is my code:
const AddPerson = () => {
const data = axios.post('http://localhost:3333/person/', {
name: name,
age: age,
profession: profession
})
console.log(data)
}