Load and access script from main process


I would like to load a script from within the main process and access it. Here is what I did from with my main process script:

const mPreferences = require('./scripts/da/local/preferences.js');

The preferences.js file is located in the scripts/da/local folder which is part of my project and the scripts folder is located directly in the root of the project. The script does get loaded. This is what preferences.js looks like:

var ROOTNS = ROOTNS || {};
ROOTNS.da = {}

ROOTNS.da.preferences = function(){
    function getLang(){
        return "english";

    return {
        getLanguage: getLang

However, when I go to access the function getLanguage, I get the response “undefined”:

var lang = mPreferences.getLanguage;

So what’s going on? Why is this returning undefined?