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

218
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 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