2 回答
TA贡献1815条经验 获得超6个赞
Server.js 文件需要对服务器进行一些正确的更改
const express = require('express');
const app = express();
const port = process.env.PORT || 5000;
//Optional: add this line to parse incoming data. In case you want to accept data
app.use(express.json());
// create a GET route
app.get('/express_backend', (req, res) => {
//generate output in `json` format rather than `send`.
res.json({ express: 'YOUR EXPRESS BACKEND IS CONNECTED TO REACT' });
});
//execute your server after writing all logic.
// console.log that your server is up and running
app.listen(port, () => console.log(`Listening on port ${port}`));
TA贡献1872条经验 获得超3个赞
感谢您的关注。随着文件夹结构的变化(在根目录中创建一个名为“backend”的新文件夹,然后将文件“server.js”移动到该文件夹中),代码现在可以工作了。谢谢 -
添加回答
举报