【发布时间】:2022-02-11 08:04:07
【问题描述】:
我正在尝试使用 Express 重新创建一个笔记应用程序。我的代码遵循讲师的示例,但是当我部署它并尝试添加新注释时,我收到错误 cannot get/api/name...我不确定我做错了什么。
在此处输入代码
const fs = require('fs');
const path = require ('path');
const express = require('express');
const dbJson = require('./db/db.json')
const {v1 : uuidv1} = require('uuid');
const PORT = process.env.PORT || 3001;
const app = express();
app.use(express.urlencoded({extended: true}));
app.use(express.json());
app.use(express.static("public"));
app.get('/notes', (req, res) => {
res.sendFile(path.join(__dirname, './public/notes.html'));
});
app.get('/api/notes', (req,res) => {
const dataNotes = fs.readFileSync(path.join(__dirname, './db/db.json'), "utf-8");
const parseNotes = JSON.parse(dataNotes);
res.json(parseNotes);
});
【问题讨论】:
标签: javascript node.js api express