Javascript – How to set and get cookies (server side) in Meteor

javascriptmeteor

How can I set and get cookies (server side) in Meteor?

Best Solution

Meteor does not currently have a supported way to use cookies on the server.

You can use cookies on the client, though. Here's a snippet to show a splash screen the first time the user visits a page:

Meteor.startup(function () {
    if (!document.cookie.match("splash="))      
      $('body').append(Meteor.ui.render(Template.splash));      
});

Template.splash.events = {
    'click .submit': function () {      
        document.cookie = "splash=ack;expires=Sat, 23 Mar 2013 00:00:0 GMT";    
        $('#splash_outer').remove();        
    }   
};

You could use a similar approach and set the cookies in client side code, then send the results to the server in a method call.