I would like to run tests of OData interfaces from node.js, using the data.js library. Unfortunately, data.js is intended for use in browsers and uses XMLHttpRequest calls. node.js cannot handle such calls because, I believe, they are implemented in the browser, not in JavaScript. Is there a module that will let me use data.js in node.js?
The usual solutions for XMLHttpRequest are OK when you can call them in your own code, but here I don't want to change data.js, so those options are not open.
Here is a sample of what goes wrong:
var odata = require("./datajs-1.1.0.js");
try{
odata.OData.read(
"http://services.odata.org/Northwind/Northwind.svc/Categories"
);
}
catch(err){
console.log ("Exception in index.js - " + err.name + ": " + err.message);
}
Running node.js index.js
:
Exception in index.js - undefined: XMLHttpRequest not supported
The exception may be a result of requiring the datajs library with a file system literal ("./") instead of as a node_module (which would be more along the lines of require("datajs")). The latter normally requires use of npm (it stands for node packaged modules), and you would want to run the following command in your project directory:
npm install datajs
The reference page for the datajs library can be found at https://npmjs.org/package/datajs. Good Luck!
There is a module for that, npm install xmlhttprequest (or similar). That module has issues with escaping... Or you can use jaydata which just works
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With