> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/web-application/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/web-application/session/how-to-store-session-data.md).

# How to store session data

기본적으로 express-session은 메모리(휘발성)에 세션 데이터를 저장하기 때문에 재접속하게 되면 데이터가 사라진다. 그래서 메모리가 아닌 파일이나 DB에 데이터를 저장하는 방법이 있다.

일단 해당하는 모듈을 설치한다.\
소스코드 내에서 해당 모듈을 불러온다. - require( )\
app.use에 store옵션으로 저장하고자 하는 것을 지정한다.

1. 파일로 저장 : 어플 실행 시 'session'이라는 디렉토리가 생성되고 여기에 세션 데이터가 저장된다.
2. mysql DB : 어플 실행 시 'session'이라는 행이 생성되고 여기에 세션 데이터가 저장된다.
3. OrientDB(NoSql) : Oriento 모듈 필요. 어플 실행 시 'session'이라는 클래스가 생성되고 여기에 세션 데이터가 저장된다.
