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

142
Vistas
Is it possible to write 'non-independent' modules in Javascript?

I have an Express-server with routes and functions, that i would like to segment into seperate files. I understand this question has been posted hundreds of times, but after browsing through 20+ threds and guides I still can't manage to find a good answer.

I have a situation that looks like this.

function securityCheck(){
   do stuff...
}

function anotherFunction(){
   do stuff...
}

app.get("/login", (req,res)=>{
   if (securityCheck()){
   do stuff...
})

app.get("/backend", (req,res)=>{
   if (anotherFunction()){
   do stuff...
})...

and I would like to have it like this

    embed(./securityCheck.js)
    embed(./anotherFunction.js)
    embed(./login.js)
    embed(./backend.js)
    ...

I understand that module.exports can pretty much do this.

However, since it's evaluating code from the relative directory of the module it self, it causes issuse with dependencies. If i use for example the securityCheck() function I have to require that locally in the module, and it also makes me reorganize my paths.

I don't have any need for the modules functionality.

Im not looking for smart ways to reuse functions or make the project modular. I just want do segment my code for the purpose of cleanliness.

The thing im looking for is something like Eval, that just runs code in it's current context that would basicly import a textfile with the code in it.

Is this possible with Javascript and Node?

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