I have module which get cookie, but didnt know how to use it in other js file


Here is code:

var Nightmare = require('nightmare');
var nightmare = Nightmare()

var startURL = 'http://somelink';

module.exports = function(email, password, work){
   .type('input[id="ctl00_cphMainContent_Login1_UserName"]', email)
   .type('input[id="ctl00_cphMainContent_Login1_Password"]', password)
   .then(function (cookies) {
   .catch(function (error) {
     console.error('Authorization failed:', error);

I was read about module.export but didnt get how my code should work with work variable, now its get object and i need to use value from it in other file like variable:

{ name: 'ASP.NET_SessionId',
  value: 'pmxqwbvzwbgk0praeirviwqy',
  domain: 'link',
  hostOnly: true,
  path: '/',
  secure: false,
  httpOnly: true,
  session: true }

Any thoughs about it? I need get value from cookie object, and use it as variable in request function.


Since the cookie is something you retrieve when a function is called in moduleA, you probably need to return the cookie from that function so the caller can get access to it. Now, since your function is asynchronous, you probably need to return a promise and make the cookies part of the resolved value of the promise. Then, you can get access to the cookies from the caller. If you want further help, then show us the code you want to use it in and how that code calls this module.



Add a Comment