관리 메뉴

Silver Library (Archived)

Node.js 로 영상 사이트 구현하기 - EP2 본문

Personal DB/Unclassified record

Node.js 로 영상 사이트 구현하기 - EP2

Ayin Kim 2021. 2. 19. 10:15
반응형

const express = require('express')

const app = express()

 

const PORT = 4000;

 

function handleListening(){

    console.log(`Listening on: http://localhost:${PORT}`);

}

 

function handleHome(req, res){

    console.log('req');

    res.send("Hello from home!")

}

 

function handleProfile(req, res){

    res.send("You are on my profile")

}



app.get("/", handleHome)

 

app.get("/profile", handleProfile);

 

app.listen(PORT, handleListening);


This handleHome function, calls two things.

1. request object

2. response object

 

Note.

If I send id or password stuff to the URL in POST way,

Then I am getting the information with the request object.

 

Keep calm and read through that bold code again.


Then what about redirecting URL with displaying the content I desired?

 

1. use app.get("/name-of-url-you-want", name of function you want to send back to user[response])

 

Then input http://localhost:4000/profile

If you can see the message you input in function handleProfile, All good!