'How to import multiple NodeJS packages together?
const metascraper = require('metascraper')([
require('metascraper-author')(),
require('metascraper-date')(),
require('metascraper-description')(),
require('metascraper-image')(),
require('metascraper-logo')(),
require('metascraper-clearbit')(),
require('metascraper-publisher')(),
require('metascraper-title')(),
require('metascraper-url')()
])
I have the following code, but const doesn't work so I have to use import
import metascraper from 'metascraper';
import title from 'metascraper-title';
import image from 'metascraper-image';
...
This does not work as expected and returns undefined - how can I import all those libraries underneath metascraper using import. Importing them manually with their own name does not work.
(async () => {
try {
// Use the got library to fetch the website content.
const targetUrl = 'http://www.bloomberg.com/news/articles/2016-05-24/as-zenefits-stumbles-gusto-goes-head-on-by-selling-insurance';
const { body: html, url } = await got(targetUrl);
// Extract the metadata from the website content.
const metascraper = await metascraper(title(),{ html, url });
// Return the metadata as JSON
console.log(JSON.stringify(metascraper));
} catch (err) {
console.log(err);
}
})()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
