index.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>
<h1>localhost:8080/ 주소로 접속하였습니다.</h1>
</body>
</html>
server.js--------------------
const express = require('express');
const app = express();
const port = 8080;
app.listen(port, () => {
console.log(`========== express 서버시작 ==========\nlistening on port ${port}`)
});
app.get('/pet', function (req, res) {
// res.send('펫용품 쇼핑할 수 있는 페이지입니다.')
res.status(200);
res.redirect('https://shopping.naver.com/window/main/pet-group?unionCategory=DOG')
});
app.get('/beauty', function (req, res) {
// res.send('뷰티용품 쇼핑할 수 있는 페이지입니다.')
res.status(200);
res.redirect('https://shopping.naver.com/beauty/home')
});
app.get('/', function (req, res) {
res.sendFile(__dirname + '/index.html')
});
// app.get('/sound/:name', function (req, res) {
// // const p = req.params
// // console.log(p.name)
// const { name } = req.params
// if (name == "dog") {
// res.json({'sound' : '멍멍'})
// } else if (name == "cat") {
// res.json({'sound' : '야옹'})
// } else if (name == "pig") {
// res.json({'sound' : '꿀꿀'})
// } else {
// res.json({'sound' : '지정되지 않았음'})
// }
// })
npm init
-entry point - server.js
npm install express
node server.js
npm install -g nodemon
nodemon server
'컴퓨터 > nodejs' 카테고리의 다른 글
Node.js 생활코딩 (0) | 2023.03.29 |
---|---|
Node.js & MySQL 생활코딩 (0) | 2023.03.23 |
callback 함수의 이해, 한글인코딩, 변수, API서버만들기, promise, async, await (0) | 2022.12.15 |
Node.js 백엔드맛보기1 (0) | 2022.01.11 |
Node.js 다음메일 여러 개 보내기 (0) | 2022.01.10 |