From the course: Building Bots with Node.js

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating a session management service

Creating a session management service - Node.js Tutorial

From the course: Building Bots with Node.js

Start my 1-month free trial

Creating a session management service

- [Instructor] To support sessions, we will first create the service that will provide us with a simple session management infrastructure. For that, I will create a new file, SessionService raw in services session. In there, I start off with class SessionService, and let's right away do this, module.exports for this SessionServices. Okay, then next we will add the constructor, and in this constructor, we basically do just some initialization because we need some object that will later hold all our sessions, so I add this.sessions equals curly brackets to initialize this empty object, and I also want to define the global timeout for my sessions, so I add this.timeout, and it should be five minutes. Next, let's add a little helper that will just give us the current timestamp, so add static now, and there I just return Math.floor, a new Date, divided by 1000, which is the UNIX timestamp in seconds. Next, we're going to…

Contents