My title pretty much describes it. I have searched the web I don't get close to what I want.
My Code:
    const Nightmare = require('nightmare')
const nightmare = Nightmare({ show: true })
var url = '';
nightmare
  .goto('https://duckduckgo.com')
  .type('#search_form_input_homepage', 'github nightmare')
  .click('#search_button_homepage')
  .wait('#r1-0 a.result__a')
  .evaluate(() => document.querySelector('#r1-0 a.result__a').href)
  .end()
  .then(function(result){
    url = result;
  })
  .catch(error => {
    console.error('Search failed:', error)
  })
//this will throw empty
console.log(url);
//basically i need a loop that can check if url has either changed values or isnt empty but only until it is not empty!
url.change(function(){
  console.log(url);
})
So I describe it mostly inside the code.
If you can help I would love that, you dont really need a basic understanding in nightmare other then it is a headless chrome npm, its basically phantom.js simplfied
 
     
    