In my Node.js app, after I require all my modules into my server.js, then I am passing their instances into my function. My function needs to figure out which module is passed and it will call corresponding file.
I tried to get module name by following way but I could not get it done.
Is there any way to extract module name? It can be object name as well.
this is my server js file
var less = require("less");
var express = require("express");
var path = require('path');
var MyApp = require("./LocalModules/MyApp.js");
MyApp.InitializeAll([less, express]);
And this is where I need to resolve module name.
exports.InitializeAll = function (modules) {
for (var i = 0; i < modules.length; i++) {
var currentModule = modules[i];
var localModuleName = "MyApp_" + currentModule.constructor.name + ".js";
var appModule = require(localModuleName);
appModule.Initialize(currentModule);
};
}