Skip to content

Instantly share code, notes, and snippets.

@k0d3d
Last active February 11, 2019 12:05
Show Gist options
  • Save k0d3d/4ef429f1a6efcec553361914eca40310 to your computer and use it in GitHub Desktop.
Save k0d3d/4ef429f1a6efcec553361914eca40310 to your computer and use it in GitHub Desktop.
Async function with nightmare
module.exports = async function (context, req) {
// keep ur module imports within
// this exported function
const Nightmare = require("nightmare");
const nightmare = Nightmare()
// @returns Promise
let n = nightmare
.goto('https://duckduckgo.com')
.type('#search_form_input_homepage', 'github nightmare')
.click('#search_button_homepage')
.wait('#links .result__a')
.evaluate(() => document.querySelector('#links .result__a').href)
.end()
let link = await n
context.res = {
body: `this is the link ${link}`
}
// U might not have to call
// this because its an async function
// context.done()
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment