Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

125
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda