A simple project demonstrating how to setup and use sessions with a node-express application. This app uses MongoDB Atlas as a session store but can either be changed to use a local instance of Mongo DB (if you don't have Atlas) or to another provider, like Redis.
Supporting repository for my medium article on Session Management-in-a-NodeJS-Express-App-with-MongoDB
If you do choose to use MongoDB as your session store, make sure to create and add the following properties to either an .env file or directly to the code. Both these environment variables are used in the session.ts file.
URI: your-mongo-db-uri
SESSION_SECRET: 217389dfb3461f357204b9a189833935ac273f97
- Download the project as a zip file or clone it to your machine.
cdinto the project folder (root) and runnpm ito install all the dependencies.- Run
npm run devto start the development server atPORT = 4000. You can change the server port value by, either adding aPORTvariable in your.envfile or change the value inindex.tsfile. - Run
npm run ts-compileto transpile typescript code to javascript.
- Nodejs
- Express.js
- MongoDB Atlas
- TypeScript