i am learning how to declare app-wide globla constatnts. referring to this post here
for the answer of Dominic Barnes
, for the code titled with constants.js -- Better
. i copied it and pasted it as shown in the following lines:
constants.js
function define(name, value) {
Object.defineProperty(exports, name, {
value: value,
enumerable: true
});
}
define("PI", 3.14);
invocation to constants.js in app.js
import constants from './constants/constants';
var req=https.get('https://xx/xx/getDistanceFromOriginToDestination/30.976639,30.056021,30.97775,30.033333',options, callback);
constants. //<==========????
req.on('error', (e) => {
console.error("problem with request:", e);
});
req.end();
the propblem is, in the post of the Dominic Barnes
he can access the PI
as follows and as shown in his answer:
var constants = require("./constants");
console.log(constants.PI); // 3.14
constants.PI = 5;
console.log(constants.PI); // still 3.14
in my case, the autocomplete of VS-Codes does not show any thing derived from constants.js
, or in other words, i can not have access to PI
.
please let me know what i am missing to chieve accessing the constant PI
declared in constants.js