Meteor - Session

Sessions are used for saving data while the users are using the app. This data will be deleted when the user leaves the app.

In this chapter, we will learn how to set a session object, store some data, and return that data. We will use the basic HTML setup.


      {{> myTemplate}}
<template name = "myTemplate">

Now, we will store myData locally using Session.set() method. Once the method is set, we can return it using Session.get() method.


if (Meteor.isClient) {
   var myData = {
      key1: "value1",
      key2: "value2"

   Session.set('mySession', myData);

   var sessionDataToLog = Session.get('mySession');

If we check the console, we will see that the stored data is logged.

Meteor Session Log

In the next chapter, we will learn how to auto-update templates using the Session variable.