app.listen() 모듈화


1. app.listen()


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

Untitled

www.js


"use strict";
const app = require("../app");
const PORT = 3000;

app.listen(PORT, () => {
  console.log("서버 실행");
});

app.js


"use strict";

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

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

//앱 세팅
app.set("views", "./views");
app.set("view engine", "ejs");

app.use("/", home);

module.exports = app;

서버 구동 명령어 변경


서버를 구동하는 app.listen()이 www.js 파일로 넘어갔으므로, 실행 명령어도

node .\\bin\\www.js 로 바꾼다.

http://localhost:3000/login

http://localhost:3000/

잘 작동하는지 확인한다.