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

116
Vistas
Is there a way to bypass the module-related code in a Node.js JavaScript file when loading it into a browser?

I have a JavaScript module that I want to use both in Node.js applications, and in applications over the Web. For Node.js uses I want to create a module object in the script and export it, so that it can be picked up in a require statement in another script file. Standard thing, e.g.:

module.exports = {
  foo: function () {
    // whatever
  },
  bar: function () {
    // whatever
  }
};

When I want to use this same script in a Web application, though, I of course use the <script> tag to import the file. However, the module code will then be flagged as unrecognized.

So my question is, is there some code I can bracket the module code with so that it gets skipped over in the browser? I wasn't a Web dev in the chaotic days of the browser wars, but I recall there being various workarounds to run different pieces of JS code depending on platform. So maybe there's something like that I can use here?

about 4 years ago · Juan Pablo Isaza
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