Question: I've recently moved from an [Express](http://expressjs.com/) web app to a [BrowserSync](http://www.browsersync.io/) app for nodejs. Using Express, if I wanted to set a cookie, my config would look something like this:

```
var express = require('express');
var session = require('express-session');
var finalhandler = require('finalhandler');
var serveStatic = require('serve-static'),
    serve = serveStatic(__dirname);

var app = express();
app.use(session({  // see https://github.com/expressjs/session
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: false
  }))
  .use(function(req, res, next) {
    res.cookie('myCookie', 'my cookie value');
    var done = finalhandler(req, res);
    serve(req, res, done);
  });
app.listen(8080);

```

My team has started using BrowserSync (via a gulp task), and my config, so far, looks something like this:

```
var gulp = require('gulp'),
    browserSync = require('browser-sync'),
    gulpLoadPlugins = require('gulp-load-plugins'),
    plugins = gulpLoadPlugins();

gulp.task('browser-sync', function() {
    browserSync({
        server: {
            baseDir: "./",
            middleware: [
                function(req, res, next) {
                    res.cookie('myCookie', 'my cookie value');
                    next();
                }
            ]
        },
        port: 8080
    });
});

```

However, the `res` object does not have a method named "cookie". Is there something similar to the [session middleware for Expressjs](https://github.com/expressjs/session) that will work as BrowserSync middleware? Is there another way to set cookies in a BrowserSync server?

Answer: 
I had the same `TypeError: res.cookie is not a function`-error. The following configuration works for me.

```
  browsersync: {
    open: false,
    port: 8080,
    server: {
      baseDir: distDir,
      middleware: [
        function(req, res, next) {
          res.setHeader('set-cookie', 'name=value');

          next();
        }
      ]
    }
  },

```
Browser-sync uses [connect](https://github.com/senchalabs/connect), which has a slightly different API than express. This configuration worked for me to add a header and a cookie to my responses using browser-sync:

```js
  browsersync: {
    open: false,
    port: 8080,
    server: {
      baseDir: distDir,
      middleware: [
        function(req, res, next) {
          res.setHeader('hello', 'world');
          res.cookie('someCookie', 'cookieVal');
          next();
        }
      ]
    }
  },

```