안녕하세요 [nodemon] app crashed - waiting for file changes before starting... 이런 오류가 계속 나와서 너무 답답해서 여쭤봅니다! 어떤 문제가 있는지 잘 모르겠어서 이렇게 글을 올립니다. 너무 어렵습니다 ㅠㅜ
const http = require("http");
const PORT = 4999;
const ip = "localhost";
const server = http.createServer((request, response) => {
const { headers, method, url } = request;
// 여기서부터 작성
let body = [];
request
.on("data", (chunk) => {
body.push(chunk);
})
.on("end", () => {
body = Buffer.concat(body).toString();
});
if (request.method === "POST" && request.url === "/upper") {
response.writeHead(200, defaultCorsHeader);
response.end(body.toUpperCase());
} else if (request.method === "POST" && request.url === "/lower") {
response.writeHead(200, defaultCorsHeader);
response.end(body.toLowerCase());
} else if (request.method === "OPTIONS") {
response.writeHead(200, defaultCorsHeader);
response.end();
} else {
response.writeHead(404, defaultCorsHeader);
response.end("Error");
}
console.log(
`http request method is ${request.method}, url is ${request.url}`
);
response.writeHead(200, defaultCorsHeader);
response.end("hello mini-server sprints");
});
server.listen(PORT, ip, () => {
console.log(`http server listen on ${ip}:${PORT}`);
});
const defaultCorsHeader = {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Content-Type, Accept",
"Access-Control-Max-Age": 10,
};