Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

212
Vistas
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);
      }
    })()
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The following should work:

import got from "got";

import _metascraper from "metascraper";
import title from "metascraper-title";
import image from "metascraper-image";
import author from "metascraper-author";
// ...

const metascraper = _metascraper([title(), image(), author()]);

try {
  // Use the got library to fetch the website content.
  const targetUrl = "https://wesbos.com/scoped-github-access-token/";
  const { body: html, url } = await got(targetUrl);
  // Extract the metadata from the website content.
  const metadata = await metascraper({ html, url });

  // Return the metadata as JSON
  console.log(metadata);
} catch (err) {
  console.log(err);
}

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda