Scope question: var undefined

Hi,

does anyone know why my config.host is undefined?

I thought, the var config should be part of the global scope (the file: server.js which we see below)

thanks.

import { Meteor } from 'meteor/meteor';
var QRS = require('qrs');
var config = {
	"host": '127.0.0.1',
	"useSSL": false,
	"xrfkey": 'ABCDEFG123456789',
	"authentication": "header",
	"virtualProxy": "hdr",
	"headerKey": 'hdr-usr',
	"headerValue": '2008ENT\\Qlik',
	isSecure: true
};

var qrs = new QRS(config);

Meteor.startup(() => {
    
    var qsocks = require('qsocks');

    var config = {
    	host: config.host,
    	isSecure: true
    };

let me quess… because it already refers to itself? the config of the function…?

Yes - the config definition in your startup function is overriding the config outside of the function. Use a different name inside your startup function, like startupConfig. If you want full details on why this is the case, read the Chapter 1: What is Scope? chapter from the You Don’t know JS: Scope & Closures book. It will take you through compiler theory and why it matters in JS.

1 Like