I am able to run this code fine from a client-side app:
$.ajaxSetup({
beforeSend: function(xhr, settings) {
xhr.setRequestHeader('Authorization', "Bearer " + myAccessToken);
}
});
$.ajax(myURL, {
dataType: 'json',
type: 'get',
success: function(data, status) {
dataReturned1(data);
},
error: function(xhr, status, error) {
console.log(xhr);
}
});
The problem comes when I attempt to run this server-side using Node.js, something like this:
var express = require('express');
var app = express();
var fs = require("fs");
var $ = require("jquery");
app.get('/sellsidebuyside', function (req, res) {
// AJAX REQUEST AS ABOVE HERE
})
var server = app.listen(8081, function () {
var host = server.address().address
var port = server.address().port
console.log("Example app listening at http://%s:%s", host, port)
})
The error message is:
TypeError: $.ajaxSetup is not a function
From online forums I gather that jQuery was perhaps never designed to run server-side, so this could be the root of my issue. It is suggested to use a standard XMLHttpRequest, but I'm not sure how to configure this to make a cross-domain request using the access token.
Please provide example JS code for a Data Fusion API call which will run server-side with Node.js?