1. js 폴더 생성


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

Untitled

login.js


"use strict";

console.log("Hello, express!");

login.ejs


<!DOCTYPE html>
<html lang="ko">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <script src="/js/home/login.js"></script>
    <title>Document</title>
  </head>
  <body>
    <input type="text" placeholder="아이디" /><br />
    <input type="text" placeholder="비밀번호" /><br />
    <button>로그인</button>
  </body>
</html>

app.js


"use strict";

//모듈
const express = require("express");
const app = express();

//라우팅
const home = require("./src/routes/home");

//앱 세팅
app.set("views", `${__dirname}/src/views`);
app.set("view engine", "ejs");
app.use(express.static(`${__dirname}/src/public`));

app.use("/", home);

module.exports = app;

http://localhost:3000/login

http://localhost:3000/

로그인 화면에 접속하면 콘솔창에 hello, express가 출력되는지 확인한다.

잘 되었다면 git add, commit, push를 진행한다.