I am trying to make a constructor function in JavaScript, and this constructor should be asynchronous, cause I am using Phantom JS module to scrape the data,so that's why I have to use asynchronous function to scrap data through Phantom JS with Node JS.
Below is my code,
const phantom = require('phantom');
async function InitScrap() {
var MAIN_URL = "https://www.google.com/",
//Phantom JS Variables
instance = await phantom.create(),
page = await instance.createPage();
// Load the Basic Page First
this.loadPage = async function() {
console.log("Loading Please wait...");
var status = await page.open(MAIN_URL);
if (status == "success") {
page.render("new.png");
console.log("Site has been loaded");
}
}
}
var s = new InitScrap();
s.loadPage()
// module.exports = InitScrap();
But when I run this code it says,
InitScrap()
is not a constructor, am I missing something ?