컨트롤러 분리


1. 컨트롤러 분리


폴더와 파일을 다음과 같이 만들고 코드를 수정한다.

Untitled

home.ctrl.js


"use strict";

const home = (req, res) => {
  res.render("home/index");
};

const login = (req, res) => {
  res.render("home/login");
};

module.exports = {
  home,
  login,
};

index.js


"use strict";

const express = require("express");
const router = express.Router();

const ctrl = require("./home.ctrl");

router.get("/", ctrl.home);
router.get("/login", ctrl.login);

module.exports = router;

http://localhost:3000/login

http://localhost:3000/

잘 작동하는지 확인한다.