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

219
Visualizações
how to get a file without requiring in node.js?

I have tons of files where I have to add this function.

const Media  = require("../../functions/Media");
Media(....);

Is there any way to:

Directly add Media() function without requiring the file

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Try declaring it as global in index file:

const {Media} = require('./functions/Media');

global.MediaGlobal = function Media(input) {
   Media(input)
}
about 4 years ago · Juan Pablo Isaza Relatório

0

It really depends on the framework you are using. You need to find the starting index file and append all global functions there. Samples are given below.

// Override Globals in Backend Nodejs

if (typeof global !== "undefined") {
  global.someGlobalFunction = function () {};
}
// Override Globals in Frontend Nodejs/reactjs
// Override Globals in Frontend javascript written on nodejs

if (typeof window !== "undefined") {
  window.someGlobalFunction = function () {};
}

Node.js + Express (Backend)

Look for file define server, app.listen, Defined on top before import other modules

Node.js + React (Frontend)

Look for file define react.render, app.jsx, Defined on top before import other modules

Learn the concept of polyfill:

Best way to polyfill ES6 features in React app that uses create-react-app

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