I want to reuse Angular2's @angular/http
module from a node script. I'm using node v4.6.0, @angular/http
version 2.1.2 from where npm
gets it.
In this specific case I want to do this so I can easily isolate the module, confirm it's behavior, and play around with it (I mean I should be able to right - that is why it's called a module..). But I'm also after general advice on reusing Angular modules that don't have inherent browser dependencies in node.
Going off how the web application I'm looking at uses the module I tried this:
myUrl = '...'
http = require('@angular/http')
Http = new http.Http()
Http.get(myUrl).then(result => console.log(result))
And got:
TypeError: Cannot read property 'merge' of undefined at mergeOptions (/home/sam/node_modules/@angular/http/bundles/http.umd.js:1578:30) at Http.get (/home/sam/node_modules/@angular/http/bundles/http.umd.js:1672:45) at repl:1:6 at REPLServer.defaultEval (repl.js:262:27) at bound (domain.js:287:14) at REPLServer.runBound [as eval] (domain.js:300:12) at REPLServer. (repl.js:431:12) at emitOne (events.js:82:20) at REPLServer.emit (events.js:169:7) at REPLServer.Interface._onLine (readline.js:212:10)
So, is it done? Can it be done? How to go about it in the specific case of Http and in general?