<@UD4701708> Before we get to your actual issue ju...
# typescript
g
@orange-tailor-85423 Before we get to your actual issue just 2 quick remarks: 1. Please do yourself and your colleagues a favor and don’t name variables
c
or any other single character 😄. It just makes reading the code harder even if it’s somewhat clear from the surrounding context what the c stands for (but consumes more brain CPU :-P). In your example I would call this variable
configFileName
instead. 2. You can turn
import fs = require('fs');
into
import * as fs from 'fs'
. Just looks more ES6 native 😉 Coming to your actual problem: In line 15 you’re loading the merged config by calling require(‘config’). This will load the merged config based on your environment variables during the first .forEach loop iteration. However in the second loop iteration - despite you having changed the environment variables - the
require('config')
call will return exactly the same thing as in the first one. In general in node.js multiple calls of require(‘asdf’) will always return the exact same thing (this also applies to ES6 imports
import ... from 'asdf'
for that matter). This is described in further detail here: https://nodejs.org/api/modules.html#modules_caching . I haven’t tried it out myself but it looks like you should be able to use https://github.com/lorenwest/node-config/wiki/Using-Config-Utilities#loadfileconfigsdirectory (e.g.
require('config').util.loadFileConfigs(path.join(__dirname, 'config'))
instead of the plain
require('config')
to load the merged config without experiencing the caching problem.