다음 글에서 만든 로그인 화면 html파일을 express로 가동시키는 서버에 띄우기

 

[HTML] 로그인 화면 만들기

1) HTML 기본 틀 작성 2) 내부에 로그인 폼 작성 아이디 비밀번호 회원가입 3) 결과 4) 전체 코드 아이디 비밀번호 회원가입

data-science-study.tistory.com

 

"use strict"

const express = require('express');
const app = express();

app.get('/', (req, res) => {
  // ``안에 html 코드 내용을 그대로 복붙('' 또는 ""가 아닌 ``사용해야 html 코드 내의 ''와 ""가 인식되어 오류 안남
  res.send(`
    <!DOCTYPE html>
    <html lang="ko">
      <head>
        <meta charset="UTF-8">
        <title>로그인</title>
        <style>
          ul {list-style:none;}
        </style>
      </head>
      <body>
        '여기는 루트입니다.'
      </body>
    </html>
  `);
});

app.get('login', (req, res) => {
  res.send(`
    <!DOCTYPE html>
    <html lang='ko'>
      <head>
        <meta charset='UTF-8'>
        <title>로그인</title>
      </head>
      <body>
        <form id="login">
          <ul>
            <li>
              <label for="id">아이디</label>
              <input type="text" id="id">
            </li>
            <li>
              <label for="pw">비밀번호</label>
              <input type="password" id="pw">
            </li>
            <input type="submit" value="로그인">
            <button onclick="location.href='sign.html'">회원가입</button>
          </ul>
        </form>
      </body>
      </head>
    </html>
  `);
});

app.listen(3000, () => {
  console.log('서버 가동');
});

 

서버를 가동시키고 주소창에 localhost:3000/login을 입력하여 /login 루트를 찾아가면 html로 작성한 로그인 화면이 뜸

'back-end > Javascript' 카테고리의 다른 글

[Node.js] Controller 분리  (0) 2022.11.22
[Node.js] 라우팅 분리  (0) 2022.11.21
[Node.js] View 분리  (0) 2022.11.20
[Node.js] https 서버 띄우기  (0) 2022.11.18
[Node.js] express 서버 띄우기  (0) 2022.11.18

+ Recent posts