Node.js httpSync error

Hi, i am trying to connect my Node.js server with Backendless, however when i try to do asynchronous calls i get an error:
This is the invoking method:


function printingClient(request, response, query) 
{




var listaPedidos = Backendless.Persistence.of(Pedido);
 var dataQueryPedidos = {condition: "ID_ESTADO = PAGADO AND ID_SUCURSAL.ID_SUCURSAL = " + query.id};
listaPedidos.find(dataQueryPedidos, new Backendless.Async(procesarRespuestaParaImpresion,capturarErores)); //--- ERROR thrown here

function procesarRespuestaParaImpresion(res)
{
response.writeHead(200, {"Content-Type": "application/javascript"});
response.write(query.callback + '(' + JSON.stringify(res.data) + ')');
response.end();
}

}

And this is the error thrown in the server




_http_outgoing.js:333
 throw new Error('"name" and "value" are required for setHeader().');
 ^
Error: "name" and "value" are required for setHeader().
 at ClientRequest.OutgoingMessage.setHeader (_http_outgoing.js:333:11)
 at new ClientRequest (_http_client.js:101:14)
 at Object.exports.request (http.js:49:10)
 at Object.exports.request (https.js:136:15)
 at Object.e._ajax_for_nodejs (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\backendless.min.js:21:167)
 at Object.A.find (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\backendless.min.js:34:178)
 at printingClient(D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\server.js:767:56)
 at Server.<anonymous> (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\server.js:106:4)
 at Server.emit (events.js:110:17)

If i try to do a synchronous request i get this error instead:

 
module.js:338
 throw err;
 ^
Error: Cannot find module 'httpsync'
 at Function.Module._resolveFilename (module.js:336:15)
 at Function.Module._load (module.js:278:25)
 at Module.require (module.js:365:17)
 at require (module.js:384:17)
 at Object.e._ajax_for_nodejs (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\backendless.min.js:21:277)
 at Object.A.find (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\backendless.min.js:34:178)
 at printingClient(D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\server.js:767:56)
 at Server.<anonymous> (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\server.js:106:4)
 at Server.emit (events.js:110:17)
 at HTTPParser.parserOnIncoming [as onIncoming] (_http_server.js:491:12)
6 Apr 14:49:14 - [nodemon] app crashed - waiting for file changes before starting...




Adding the httpsync module does nothing as it is not official and now it’s been deprecated.
Your help is kindly appreciated as in the example on the blog you do not make any actual requests. The login works fine in async (not in sync though) but not the queries themselves. I am using the last SDK
Best Regards,
Nicolas

Did you do Backendless.initApp in your code?

Mark

Yes, after server start i invoke this method:

var logueadoBE = conectarBE(0);
/realiza la conexión por primera vez con el servidor de BE
function conectarBE(intentos) {


	var APPLICATION_ID = 'XXX',
		SECRET_KEY = 'XXXX',
		VERSION = 'v1'; //default application version;
	Backendless.initApp(APPLICATION_ID, SECRET_KEY, VERSION);


	var u = 'aXXX';
	var p = '1XXXX';
	try {
		Backendless.UserService.login(u, p, new Backendless.Async(function(x) {
			user = x;
			user.___class = "Users";
		}, capturarErores));
	} catch (err) // Si no se logra conectar y si ha intentando 10 veces, pause 10 segundos y reintente de nuevo
	{
		console.log("No se pudo loguear en backendless!\n\n\nerror message - " + err.message);
		if (intentos % 10 !== 0)
			conectarBE(++intentos);
		else //
		{
			setTimeout(function() {
				console.log("Reintentando conexion BE: " + intentos);
				conectarBE(++intentos)
			}, 10000);
		}


	}


	console.log("se logueo backendlessHTML");


	return true;
}

as a side note, on the not minified version the error is at these lines:

at Object.Backendless._ajax_for_nodejs (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\backendless.js:386:29)
at Object.DataStore.find (D:\Dropbox\Dropbox\Comete Alguito 3.0\Desarrollo\Server Side Code\Pure NodeJS\backendless.js:932:34)

I’ve tracked the issue to the login service as returning the user token with an undetermined value. This is the consequence of the login process, as the user received comes in the form of a string object in this form:

    0: "{" 1: """ 2: "o" 3: "w" 4: "n" 5: "e" 6: "r" 7: "I" 8: "d" 9: """ 10: ":" 11: "n" 12: "u" 13: "l" 14: "l" 15: ","

Hi! i wonder if there is any solution for this issue, as currently i cannot execute any backendless operation from nojde.js

We have not looked into it yet, but it is in the support queue. We will update this post as soon as the problem is investigated.

Hi Nicolas,

Could you please re-run it with the attached library? We made a few changes and would like you to verify it (please make sure to unpack the zip file).

Thanks,
Mark

backendless.min.js.zip (13.77kB)

Hi Mark,

With the new API this is what i get for user:

""0":"D","1":"O","2":"\\","3":"\"","4":",","5":"\\","6":"\"","7":"D","8":"I","9":"R","10":"E","11":"C","12":"C","13":"I","14":"O","15":"N","16":"\\","17":"\"","18":",","19":"\\","20":"\"","21":"c","22":"r","23":"e","24":"a","25":"t","26":"e","27":"d","28":"\\","29":"\"","30":",","31":"\\","32":"\"","33":"e","34":"m","35":"a","36":"i","37":"l","
38":"\\","39":"\"","40":",","41":"\\","42":"\"","43":"u","44":"p","45":"d","46":"a","47":"t","48":"e","49":"d","
50":"\\","51":"\"","52":",","53":"\\","54":"\"","55":"o","56":"b","57":"j","58":"e","59":"c","60":"t","61":"I",
"62":"d","63":"\\","64":"\"","65":",","66":"\\","67":"\"","68":"n","69":"a","70":"m","71":"e","72":"\\","73"
:"\"","74":",","75":"\\","76":"\"","77":"B","78":"A","79":"N","80":"K","81":"_","82":"C","83":"O","84":"D"
,"85":"E","86":"\\","87":"\"","88":",","89":"\\","90":"\"","91":"D","92":"O","93":"C"," ..... "711":"}"}"

Note that this time is a String insted of an array.

Hi, Nicolas! Try this backendless.js and use all requests with Async argument. Tell me if it works, please.
I add backendless.min lib in txt format. Just change .txt format to .js and add to your project

backendless.txt (49.23kB)

A have just tested it for a while but everything seems to be alright this time :). User is still a String, but i guess that is the intended behaviour for the headers. Thank you very much guys for your support, you are awesome.