How did you decide which was the correct settings file? I am having exactly the same issue...
I am editing home/pi/.node-red/settings.js
The JS file is part of a node_module that I installed. The node_module is in /home/pi/.node-red/node_modules/dateformat and the js file is in /home/pi/.node-red/node_modules/dateformat/lib/dateformat.js
At first, instead of the path to the JS file, I tried simply dateformat.require("dateformat") but that didn't work either.
this all works in Visual Code Editor running as a node.js module.
in node-red function node I have...
var dateFormat = global.get("dateformat");
var theDate = new Date(msg.payload);
var formattedDate = dateFormat(theDate, "ddd dd-mmm-yyyy");
msg.payload = formattedDate;
return msg;
And the response I get is TypeError: dateFormat is not a function
I can't find any useful documentation on how to do this.
The node module must conform to the conventions!
In the module folder "dateformat" must be the index.js which includes the sub-modules in the lib folder.
It is also possible to type the code direct in the index.js.
What I learned is this: when I hit Ctrl-C on the node-red console, it chops the console but it doesn't chop the node-red service, so I had been making edits, hitting Ctrl-C in the console and then kicking off the service again. That did not recycle the service and so did not pick up my changes. I learned that after the Ctrl-C, I need to run node-red-stop followed by node-red-start in order to deploy my changes.
So, backing out stuff I didn't need...
I didn't need to add an exports command to my dateformat.js
I didn't need to have an index.js file in the dateformat folder - it had already been installed as a node using npm install and that was sufficient.