[node][mocha]Global variables not accessible when testing with mocha
问题 I'm trying to create a unit test for express node application. I want the configuration used for the test to be different than the one used in production, so I implemented the following. In my index.js , I load the configuration into the global variable like this: global.env = {}; global.env.config = require('./config/config'); // Create the server ... server.listen(3000); module.exports = server; In some other controller myController.js , I access the global variable like this var Config =