Marcel Wolf Marcel Wolf - 1 year ago 81
Node.js Question

Add additional file to global path in nodeJS

I am new to NodeJS/ JavaScript and I want to add an additional File to my Global variable Declaration. My Idear:

I want do add a Language File to my Global Path

var getLanguage = require('./language.js');
module.exports = {
retryAssertionTimeout: 2000,
language: getLanguage.de_de,

In Language File I have Two Definitions, one for german and one for english.

So if I change

language: getLanguage.de_de,


language: getLanguage.en_en,

i want to change the used langugage.

the declaration in my language file looks like:

module.exports = {
de_de: {
verzeichnisse: "Verzeichnisse",
benachrichtigungen: "Benachrichtigungen",
berichte: "Berichte",
ftp_server: "FTP Server",

in my functions i call it with

var data = client.globals;
var language = data.language;
.goto(language.benutzer) //Benutzer is declared in my full file.

but this just not work.

Any idears?

Answer Source
var chinese = {
    game : "游戏"

var english = {
    game : "game"

function getLanguage(type) {
    if (type == 1) {
        return chinese;
    } else if (type == 2) {
        return english;

exports.getLanguage = getLanguage;

var getLanguage = require('./language.js');
var language = getLanguage.getLanguage(1);

{ game: '游戏'}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download