-1

I have a large .js file with towards 800 variables with strings and arrays with more strings in them, which i all want to be able to access. I am currently using require('filename') to import them, but for it to work i need to have a module.exports array where i put in all the variables.

It currently works, but for me to be able to use all the variables in the file, i would have to add them all to the array.

//Main file:

const LANG = require('./Languages/Menu_' + CONFIG.language);

//File to import:

module.exports = { M, TestVar, LangAbbreviation, And800MoreVariables }

It does work, but i would have to add all 800 variables to the module.exports. which is a lot of manual labor, which i might have to do more than once as well.

Is there a way to import the variables like in without having to specify that they should be exported? Something similar to #import in C.

Sorry if i am missing some information. I am new to Javascript in general, please ask if more is needed.

Jaco9307
  • 13
  • 7

2 Answers2

0

You can put all the things which you want to export inside module.exports object. something like this:

module.exports = {
  name: 'Mike',
  city: ['Bangalore','New York'],
  foo: function(){
    return `${this.name} from ${this.city[1]}`
  }
}

click here for in-depth answer

-1

Not sure you have choice. And also at this point i might consider you to abuse module.export hahaha

The only thing to make it better is

const languageConfig = { 
  M, 
  TestVar, 
  LangAbbreviation, 
  And800MoreVariables,
}

module.exports = languageConfig

Depends on your code, you might need good abstraction for this object.

Nikko Khresna
  • 1,024
  • 8
  • 10