서버를 만들었을 때 공통적으로 실행을 시켜주고 싶은 것이 있을 때, 예를 들어 아래 코드를 보자
app.get('/', (req, res) => {
console.log('모든 요청에 실행하고 싶어요')
res.sendFile(path.join(__dirname, 'index.html'));
});
app.post('/', (req, res) => {
console.log('모든 요청에 실행하고 싶어요')
res.send('hello express');
});
app.get('/about', (req, res) => {
console.log('모든 요청에 실행하고 싶어요')
res.send('hello express');
});
위 처럼 공통적으로 실행하고 싶은 코드가 있을 때, 일일이 하나하나 넣어주면 불필요한 코드의 반복이 된다. 때문에 미들웨어라는 개념이 등장했다.

app.get('/category/:name', (req, res) => {
res.send(`hello ${req.params.name}`)
})
위 처럼 :name 처럼 :를 붙여주고 매개변수를 붙여줌, 이후 send에서 백틱 ${req.params.매개변수}로 선언가능하다

하지만 코드가 위에서 밑으로 실행되기 때문에 만약 아래와 같은 코드에서
app.get('/category/:name', (req, res) => {
res.send(`hello wildcard`)
})
app.get('/category/java', (req, res) => {
res.send(`hello java`)
})
위와 같이 실행할 경우 hello wildcard가 출력이 된다. 왜냐하면 코드가 위에서 부터 실행되다가 /category/:name을 만나서 hello wildcard가 출력된 후 next() 가 없기 때문에 다음 코드로 내려가지 않게 되기 때문.
따라서 와일드 카드 (:name) 을 쓰려면 다른 코드보다 밑에 존재해야 한다.
app.get('/category/java', (req, res) => {
res.send(`hello java`)
})
app.get('/category/:name', (req, res) => {
res.send(`hello wildcard`)
})
마찬가지로 app.get('', 콜백함수)도 마찬가지이다
app.get('')을 하면 ''이 모든 경로를 의미하기 때문에, 제일 상단에 존재할 시 다른 경로들은 실행이 되지 않게 된다. 때문에 '' 또는 wildcard는 코드 하단에 존재하는것이 좋습니다.