Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!