in realier days I saw somewhere that we can configure node-js to execute a loaded module in the global scope, I can't find how to do that now.
Why I'm asking?
I have some legacy files that define language utilities that I want to use on both the server and on the client, however many of these utilities are defined as global scope functions.
For example, I have functions like closure(fClosure)
, module(fModule)
, and many more that simply organize your code in readable definitive way, and utilities like $sb(arg,arg,arg)
, that is a string builder, and so on.
Now these utilities are defined in a file like core.js
, and this file is loaded into the browser as first dependency, and life are good.
But, requiring this file in the root helps in places where it extends Array.prototype
, but it functions that are defined in it are not visible in other modules.
(and please avoid the discussion of polluting or colliding with other libs)
I know it's not according to the CommonJS specifications... but now I'm just trying to leverage this legacy codes without reorganizing all the codes in a CommonJS way.
I aslo found about RequireJS and the beautiful AMD model it proposes, but it answers only on how to run on the browser codes that are written for node.js, and not vice-versia.
Assigning to the global variable will not work, because it means I have to rewrite all the legacy libraries. I am looking for a way to make them run on the global scope and leave all what they declare there, without rewriting them.
So, is there a way to ask node to require a file and run it on the global scope?