const http = require('http');
const fs = require('fs');

const users = {};

http.createServer((reqres=> {
    if (req.method === 'get') {
        if(req.url === '/') {
            return fs.readFile('./restfront.html', (err,data=> {
                if(err){
                    throw err;
                }
                res.end(data);
            });
        } else if (req.url === '/about') {
            return fs.readfile ('./about.html', (err,data=> {
                if (err){
                    throw err;
                }
                res.end(data);
            });
        } else if (req.url === '/users') {
            return res.end(json.stringify(users));
        }
        return fs.readFile('.${req.url}', (err,data=> {
            if (err){
                res.writeHead(404'not found');
                return res.sendDate('not found');
            }
            return res.emd(data);
        });
    } else if (req.method === 'post') {
        if (req.url === '/users') {
            let body = '';
            req.on('data', (data=> {
                body += data;
            });
            return req.on('end', () => {
                console.log('post 본문(body):' , body);
                const {name= jason.parse(body);
                const id = date.now ();
                users[id= name;
                res.writeHead(201);
                res.end('등록 성공');
            });
        }
    } else if (req.method === 'put') {
        const key = req.url.split('/') [2];
        let body = '';
        req.on('data', (data=> {
             body += data;
        });
        return req.on('end', () => {
            console.log'put 본문(body):'body);
            users[key= json.parse(body).name;
            return res.end(json.stringify(users));
        });
    }
else if (req.method === 'delete') {
    if(req.url.startswith ('/users')) {
        const key = req.url.split('/')[2];
        delete users[key];
        return res.end(json.stringify(users));
    }
}
res.writeHead(404,'not found');
return res.end('not found');
})
  .listen(8085, () => {
      console.log('8085번 포트에서 서버 대기 중입니다.,');
  });


뭐가 문제냐?