Skip to content

Instantly share code, notes, and snippets.

@linux08
Created December 16, 2018 00:29
Show Gist options
  • Save linux08/02298afcb1a1ed44bb84d2b887d766b4 to your computer and use it in GitHub Desktop.
Save linux08/02298afcb1a1ed44bb84d2b887d766b4 to your computer and use it in GitHub Desktop.
exports.getNews = async (req, res) => {
const { address } = req.query;
const webAddress = `https://${(address || 'news.ycombinator')}.com`;
try {
const browser = await puppeteer.launch();
const page = await browser.newPage();
await page.goto(`${webAddress}`, { waitUntil: 'networkidle2' });
await page.pdf({ path: `./assets/news.pdf`, format: 'A4' });
await browser.close();
res.send('File saved');
}
catch (err) {
res.status(500).send(err.message);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment