I'm struggling with the asynchronicity of javascript using https://github.com/segmentio/nightmare to save its scraped data to a variable.
var Nightmare = require('nightmare');
var nightmare = Nightmare();
var title = nightmare
.goto('https://github.com')
.evaluate(function () {
return document.title;
})
.end()
.then((result) => {
// console.log(result);
});
console.log(title);
The console output looks like: Promise { <pending> }
How do I store the result to the title
variable before the console will log? Am I supposed to use generator functions with yield
?