본문 바로가기

Lecture

Render

JS

app.get('/',(req,res)=>{ //request, respond app.get('/',(a,b)=>{})

    res.render('index.html',{
        title : req.query.name,
        user_id : req.query.id,
        user_pw : req.query.pw,
    });
    
});

 

 

HTML

<!DOCTYPE html>
<html lang="en">
<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">
    <title>Document</title>
</head>
<body>
    Hello World! {{title}} <!--template 제공--><br>
    ID : {{user_id}} <br>
    Password : {{user_pw}}

</body>
</html>

 

 

DEFAULT : nunjucks를 이용해서 html과 js연결해 둔 상태.

 

브라우저에 http://localhost:3000/?name=asdf&id=web7722&pw=1234 << 이렇게 request값을 입력해줌

 

request값으로 name, id, pw를 받아온후 respond로 html에서 만들어논 공간(템플릿)안에 받아온 값들을 입력해준다.

 

결과물:

 

'Lecture' 카테고리의 다른 글

FORM tag  (0) 2021.04.20
query  (0) 2021.04.20
서버 여는 법  (0) 2021.04.20
view engine : nunjucks  (0) 2021.04.20
express 설치 방법  (0) 2021.04.20