voltace / browser-cookies

Tiny cookies library for the browser
The Unlicense
89 stars 18 forks source link

Error: document is not defined #13

Closed dallashuggins closed 6 years ago

dallashuggins commented 6 years ago

Hi there,

I'm having an issue using the cookies.all() function.

Below is the script I am using:

var allCookies = cookies.all(); 
for (var key in allCookies) {
   cookies.set(key, allCookies.key);
}

This throws an error every time I run it:

Unhandled rejection ReferenceError: document is not defined
    at Object.exports.all (/home/ubuntu/workspace/node_modules/browser-cookies/src/browser-cookies.js:74:33)
    at rp.post.then.firstloginResp (/home/ubuntu/workspace/modules/login.js:148:32)

The login.js:148.32 points to the inside of the parentheses in var allCookies = cookies.all();.

Any idea how I can fix this?

voltace commented 6 years ago

The 'browser-cookies' module is meant for JavaScript applications that run in web browsers. I'm not sure about the context in which the code fragment above is run, is it perhaps executed server side (e.g. nodejs)?

dallashuggins commented 6 years ago

Hi @voltace: I am using it with node js. Thank you for the clarification!