View our GitHub

Please visit sails-docs on GitHub to view documentation on your mobile device.

Edit Page


Sets a cookie with name (name) and value (value) to be sent along with the response.


res.cookie(name, value [,options]);


The "path" option defaults to "/".

The "maxAge" option is a convenience option for setting "expires" relative to the current time in milliseconds. The following is equivalent to the previous example.

res.cookie('rememberme', '1', { maxAge: 900000, httpOnly: true })

An object may be passed which is then serialized as JSON, which is automatically parsed by the bodyParser() middleware.

res.cookie('cart', { items: [1,2,3] });
res.cookie('cart', { items: [1,2,3] }, { maxAge: 900000 });

Signed cookies are also supported through this method. Simply pass the signed option. When given res.cookie() will use the secret passed to express.cookieParser(secret) to sign the value.

res.cookie('name', 'tobi', { signed: true });


res.cookie('name', 'tobi', {
  domain: '',
  path: '/admin',
  secure: true

res.cookie('rememberme', '1', {
  expires: new Date( + 900000),
  httpOnly: true

Is something missing?

If you notice something we've missed or could be improved on, please follow this link and submit a pull request to the sails-docs repo. Once we merge it, the changes will be reflected on the website the next time it is deployed.


We wrote a book!

Get early access to the book
with promotion code: mcneildoc

Get the Book