0

I have ex1.js and ex2.js. And in ex2.js I want to get variable which one is in ex1.js

I can read the file, but I want to get exactly this var Value.

 var fs = require('fs');
 var readMe = fs.readFileSync('path', 'utf8');
 console.log(readMe); 
Shaharyar
  • 12,254
  • 4
  • 46
  • 66
Dima
  • 19
  • 1
  • 5

1 Answers1

0

As long as they are both JavaScript files this is how it is generally done.

// in the js2 file
exports.var_js2 = 15;

// in the js1 file
var_js2 = require('./js2').var_js2
bezzoon
  • 1,755
  • 4
  • 24
  • 52