# Session with Express

세션방식으로 count 페이지(count값이 1씩 증가하는 페이지)를 만들어보겠다. \
코드 설명 :\
&#x20; req.session객체를 통해 'count'라는 데이터를 심고, 값은 1로 셋팅한다.

```
app.get('/count',(req,res)=>{
     req.session.count = 1;
     res.send('hi session');
 });
```

sid(session id)로 접속한 사용자는 서버에 count라는 값으로 '1'이 저장되어 있고, 이 값은 우리가 직접 req.session.count로 저장할 수도 있지만, req.session.count로 값을 읽어올 수도 있다.\
req.session.count는 일종의 쿠키 데이터인듯하다.\
**session의 핵심**은, **sid별로 별도의 데이터를 서버에 저장할 수 있다**는 것이다..

**express-session** 이라는 모듈은 기본적으로, 사용자의 정보를 **메모리에 저장**한다. 그렇기 때문에 해당 서버(어플리케이션)을 껐다 켜면 정보는 날아간다.

모듈명 사용할 때 주의하기!\
'express-session' 을 'session'이라고 해서 터미널에서 'session'이라는 모듈을 못 찾아 무한루프(?)에 빠지게 되어 맥북을 몇 번 껐다 켰는지 모른다..터미널 셋팅하는 방법도 헤매서..\
결론 : 모듈명을 정확하게 기술하고, 터미널 다시 새로 살리는 방법 익히기..!


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://heunnajo.gitbook.io/web-application/session/session-with-express.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
