Node support
Wizek opened this issue · 1 comments
Hello!
I'm very glad this project exists, as I came to prefer Angular's DI to node's require over the past few months, mainly for testability reasons. I'm sure I don't have to depict the subject matter to you too much. 😄
Now, my issue seems very simple: I tried echo "require('ng-di')" | node
and I get this error:
/home/wizek/sandbox/loader/node_modules/ng-di/dist/ng-di.js:80
sie = int((/msie (\d+)/.exec(lowercase(window.navigator.userAgent
^
TypeError: Cannot read property 'userAgent' of undefined
at /home/wizek/sandbox/loader/node_modules/ng-di/dist/ng-di.js:80:76
at Object.<anonymous> (/home/wizek/sandbox/loader/node_modules/ng-di/dist/ng-di.js:1857:3)
at Module._compile (module.js:449:26)
at Object.Module._extensions..js (module.js:467:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:362:17)
at require (module.js:378:17)
at [stdin]:1:1
at Object.<anonymous> ([stdin]-wrapper:6:22)
I looked into the source files and I saw multiple references to the window object. Node doesn't have a global variable called window
, instead it has a global variable called global
.
Or did I miss something? Does it work for you in Node?
If not, I'll do a little more looking, maybe I find an easy solution. In that case, would you accept my pull request?
Hey!
Thanks for your feedback! Currently the version in master works only in browser due to some extra angular features i needed to add in order to have several of their core providers working standalone in a browser environment.
It has not a quick solution for the dual compatibility, but I'll try to find a good solution for isolating core and providers related code during next weeks.
In the meanwhile, the v0.0.2 published at npm repository should work in node.
Please, use it and see if it fits your needs by using
npm install ng-di@0.0.2
And collaboration is always welcome!