How to send cookies with node-fetch?

Skay picture Skay · Jan 15, 2016 · Viewed 26.3k times · Source

I've got nodejs application which handles user's requests and receives cookies which i want to proxy to internal API service. How to approach this by using node-fetch?

Don't offer superagent please.

Answer

plemarquand picture plemarquand · Feb 7, 2016

You should be able to pass along cookies by setting it in the header of your request:

const opts = {
    headers: {
        cookie: 'accessToken=1234abc; userId=1234'
    }
};
const result = await fetch(`/some/url`, opts);