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

126
Vistas
Do variables defined in index.js transfer over to other scripts?

I have index.js running the following code:

var ClassData=require("./server/classdata.js");
var data=require("./server/data.js");

The classdata.js file contains multiple classes, and I was wondering if there is any way to get that into data.js. As of now, the following code is:

var data={};

console.log("hello1"); //this gets logged
module.export=data;
console.log("hello2"); //this gets logged

console.log(ClassData); //"ClassData is not defined"

The data object gets exported when the last line is not there, otherwise with it there it says that ClassData is not defined. I know I can probably define it using the same way I did in index.js, using require();, but I would think that makes it run the whole script again. Is there a way to just get it straight from data.js such that it is defined? Would I need to put it in the data.require part? I don't care if I can't change ClassData.

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

The classdata.js file contains multiple classes, and I was wondering if there is any way to get that into data.js

You can use require('./classdata.js') inside of data.js, that is what require is for, reusing a module inside another.

I know I can probably define it using the same way I did in index.js, using require();, but I would think that makes it run the whole script again.

Modules imported with require are cached after their first use so the script will not run again.

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