Answer the question
In order to leave comments, you need to log in
How to connect React with NodeJS?
Trying to make a simple React connection with NodeJS.
React backend connection:
axios({
method: 'GET',
url: 'http://localhost:8000',
headers: {
"Content-Type": "application/json"
}
}).then(response => {
console.log(response.data.message)
})
const express = require('express')
const cors = require('cors')
const app = express()
app.use(cors)
app.get("/", (request, response) => {
response.send({ message: "We did it!" })
})
app.set('port', process.env.PORT || 8000)
app.listen(app.get('port'), () => {
console.log(`Server is running on PORT: ${app.get('port')}`)
})
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question