text: const express = require("express");
  const nedb = require("nedb");
  const session = require("express-session");
  const dotenv = require("dotenv");
  const cors = require("cors");
  
  const app = express();
  dotenv.config();
  const port = 3000;
  
  const db = new nedb({ filename: "user.db", autoload: true });
  
  app.set("views", "./views");
  app.set("view engine", "pug");
  
  app.use(cors());
  app.use("/src", express.static(__dirname + "/src"));
  app.use(express.json());
  app.use(
    session({
      secret: "baemin-8",
      resave: false,
      saveUninitialized: true,
      name: "baemin",
    })
  );
  
  app.get("/", function (req, res) {
    res.render("main");
  });
  
  app.get("/login", function (req, res) {
    res.render("login");
  });
  
  app.get("/approval", function (req, res) {
    res.render("approval");
  });
  
  app.get("/phone", function (req, res) {
    res.render("phone");
  });
  
  app.get("/signup", function (req, res) {
    res.render("signup");
  });
  
  app.post("/user", function (req, res) {
    const data = req.body;
    db.insert(data, (err) => {
      if (err) {
        console.log(err);
        res.status(404).send("Not found");
        return;
      }
      res.redirect("/login");
    });
  });
  
  app.post("/login", function (req, res) {
    const { email, password } = req.body;
  
    db.find({ email }, (err, [result]) => {
      if (err) {
        console.log(err);
        res.status(500).send("Not found");
        return;
      }
  
      if (!result) {
        res.status(404).send({ message: "아이디가 없습니다!" });
        return;
      }
      if (result.password !== password) {
        res.status(401).send({ message: "비밀번호가 다릅니다!" });
        return;
      }
      req.session.user = result.nickname;
      res.status(200).send({ nickname: result.nickname });
    });
  });
  
  app.post("/check", function (req, res) {
    if (!req.session.user) {
      res.send({});
      return;
    }
  
    res.status(200).send({ nickname: req.session.user });
  });
  
  app.listen(process.env.PORT || 3000, () => {
    console.log(`Example app listening at http://localhost:${port}`);
  });
  