【发布时间】:2021-01-15 00:29:57
【问题描述】:
我对编码还是很陌生,目前正在探索 Express。我遇到了这个问题“,”虽然我尝试按照说明添加它,但它仍然显示:(
const express = require("express"); const fs = require("fs")
const app = express();
const PORT = 3000;
app.get('/products', (req, res) => {
fs.readFile('./masterdata/products.json', (err, data) => {
if(err){
res.status(400).json({
message: "Something wrong when loading the data"
})
res.status(200).json(JSON.parse(data))
// res.json([
// "Apple",
// "redmi",
// "One plus"
// ])
}
} }),
app.get('/orders', (req, res) => {
res.json([
{
id: 1,
paid: false,
user_id: 1
},
{
id: 2,
paid: true,
user_id: 2
}
])
})
app.listen(PORT, () => {
console.log(`Server Listening on port ${PORT}`); })
我收到的错误消息是 (',' expected.)
请帮我弄清楚。很感谢任何形式的帮助。非常感谢!
【问题讨论】:
-
请正确格式化代码(使用代码格式,而不是引号格式)并告诉哪一行抛出错误。