- 오늘자 강의 완강
- 코테 문제 풀이
- 멘토링 정리
- adsp 1,2과목 강의 완강
- 취준 계획표 작성 및 제출
(어제 강의에서 이어서.. )
객체를 담은 map을 만들어보자.
import express from 'express'
const app = express()
app.listen(3002, () => {
console.log('Server is running on http://localhost:3002')
})
app.get('/:id', function (req,res) {
let {id} = req.params
id = parseInt(id)
if(db.get(id) == undefined){
res.json({
maessage: "없는 상품입니다."
})
}
else {
let product = db.get(id)
product.id = id
product["id"] = id
res.json(product)
}
})
let notebook = {
productName : "Notebook",
price : 2000000
}
let cup = {
productName : "Cup",
price : 3000
}
let chair= {
productName : "Chair",
price : 20000
}
let poster= {
productName : "Poster",
price : 20000
}
let db = new Map()
db.set(1, notebook) // 키로 벨류를 찾을 수 있는 한 쌍을 저장
db.set(2, cup)
db.set(3, chair)
db.set(4, poster)
console.log(db)
console.log(db.get(1))
console.log(db.get(2))
console.log(db.get(3))

id 추가하는 법 확인하자!!
product.id = id
product["id"] = id
🤨 여기까지 복습!
//express 모듈 셋팅
import express from 'express'
const app = express()
app.listen(3004, () => {
console.log("Server is running on http://localhost:3004")
})
// 데이터 셋팅
let youtuber1 = {
channelTitle : "YES24",
sub : "20.1만명",
videoNum : "1.2천개"
}
let youtuber2 = {
channelTitle : "해쭈 [HAEJOO]",
sub : "82.7만명",
videoNum : "507개"
}
let youtuber3 = {
channelTitle : "딩고 뮤직 / dingo music",
sub : "547만명",
videoNum : "3.2천개"
}
let db = new Map()
db.set(1, youtuber1) // 키로 벨류를 찾을 수 있는 한 쌍을 저장
db.set(2, youtuber2)
db.set(3, youtuber3)
// REST API 설계
app.get('/youtuber/:id', function(req, res){
let {id} = req.params
id = parseInt(id)
const youtuber = db.get(id)
if(youtuber == undefined){
res.json({
message : "유튜버 정보를 찾을 수 없습니다."
})
} else {
res.json(youtuber)
}
})
app.get('/', function(reqs, res){
res.send('Hello World')
})
express 구조 알아보기
express 홈페이지 톺아보기
Express - Node.js web application framework
Express is a fast, unopinionated, minimalist web framework for Node.js, providing a robust set of features for web and mobile applications.
expressjs.com

웹 프레임 워크 : 내가 만들고 싶은 웹 서비스를 구현하는 데 필요한 모든 일을 틀 안에서 할 수 있는 것

Express 애플리케이션 설치하기
https://expressjs.com/en/starter/generator.html
프로젝트로 시작할 때에는 generator 써서 협업 때의 규칙으로 쓸 수 있음.
Express application generator
Learn how to use the Express application generator tool to quickly create a skeleton for your Express.js applications, streamlining setup and configuration.
expressjs.com
sudo npm install express-generator -g
express


폴더들이 생성됨!

생성된 bin > www.js 과 app.js 뜯어보자!
[www.js]
var app = require('../app');
var debug = require('debug')('express-base:server');
var http = require('http');
모듈을 가져옴.
debug : 어떤 부분이 돌아가고 있는 지 log찍어주는 모듈
var port = normalizePort(process.env.PORT || '3000');
app.set('port', port);
포트 설정
var server = http.createServer(app);
서버 실행
server.listen(port);
server.on('error', onError);
server.on('listening', onListening);
포트 연결
이 파일이 뒤에서 열심히 일해주고 있었구나!
[app.js]
var app = express();
app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use(express.static(path.join(__dirname, 'public')));
미들웨어 역할
use : 연결 역할
module.exports = app;
모듈로 수출
index.js을 실행해보자.
npm install
package.json에 있는 dependencies 모두 다운로드
npm start

https://ilove-ya.tistory.com/116
한 번에 더 정리하면 좋을 것같아서 따로 글을 작성했다.
[Node.js] express-generator로 Express 구조 해부해보기
🤔 express-generator가 뭐지?npx express-generator👉 Express 서버의 정석 폴더 구조를 자동으로 만들어주는 도구 // 패키지 설치npm install// 프로젝트 구동npm startnpm install는 package.json의 dependencies에있는 모
ilove-ya.tistory.com
자바스크립트 함수 선언 방법
function add1(x,y){
return x+y;
}
//위의 것을 모듈화 하기 위함
let add2 = function(x,y){
return x + y
}
//화살표 함수 (arrow function)
//function 대신 =>
const add3 = (x,y) => {
return x + y
}
//return으로 한번에
var add4 = (x,y) => x + y
console.log(add1(1,2))
console.log(add2(1,2))
console.log(add3(1,2))
console.log(add4(1,2))
'Devcourse' 카테고리의 다른 글
| [프로그래머스 데브코스 풀스택] 2026-01-27 TIL foreach문, map 함수, 리팩토링, HTTP 상태 코드 (0) | 2026.01.27 |
|---|---|
| <프로그래머스 데브코스 풀스택> 2026-01-26 TIL (0) | 2026.01.25 |
| [프로그래머스 데브코스 풀스택] 2026-01-22 TIL (0) | 2026.01.21 |
| <프로그래머스 데브코스 풀스택> 1차 역량평가 준비 (0) | 2026.01.20 |
| <프로그래머스 데브코스 풀스택>2026-01-19 TIL (0) | 2026.01.19 |