NodeJS scripts timing out with 504

Hi,

I’m testing several NodeJS scripts (in the web Files area), and it seems that every time I get some sort of error in the code, I get a 504 error - timed out. I have temporarily upgraded to the Plus plan to get 20 seconds of run time, but the scripts always seems to time out in 7 - 10 seconds.

Is this normal behaviour? I am really struggling to find a way to see what is going on without stepping through the code one line at a time and calling response.send() with debugging.

On another note, how advanced can the NodeJS be? I have an object with prototype methods, but I cannot get it to run.

Thanks

Hi, Paul,

Please, provide some examples of the code which is causing the described problems. We’ll try to reproduce them and then will be able to give you an answer.
Regards,
Sergey

I have one script called MemberGame.js

function MemberGame(args)
{
	args = args || {};
	this["___class"] = "MemberGame";
}


MemberGame.prototype.hello = function()
{
    
};


module.exports = MemberGame;

I have a second script ‘savemembergame.js’. It contains:

var MemberGame = require('./MemberGame');
var memberGame = new MemberGame();
memberGame.hello();
response.send(memberGame);

When I call this script, I get: TypeError: undefined is not a functionIf I remove line 3, it returns a the MemberGame object

OK thanks, we’ll check this use case.

Looks like you provided the full savemembergame.js script, and I thought this is just a fragment. In this case you’re not using exports.run function - this is what causes TypeError: undefined is not a function.
Your executable script should look like the following:

exports.run = function( request, response )
{
    var MemberGame = require('./MemberGame');
    var memberGame = new MemberGame();
    memberGame.hello();
    response.send(memberGame);
}

I am using that way, but I am using the “require” outside of the exports.run, like in your examples, i.e. you don’t put require in the exports.run = function …


var MemberGame = require("./MemberGame");


exports.run = function(request, response)
{
  var memberGame = new MemberGame();
  memberGame.hello();
  response.send(memberGame);
};

I just tried your code and it returned {"___class":“MemberGame”}, no error.
Are your files savemembergame.js and MemberGame.js in the same folder?

Yes they are, but this is just a sample of what I’m using, there is a lot more code. Is there anything you can’t do in NodeJS script code (not that I’m doing anything specific) to help me track down my issue?

My JavaScript object has about 20 “methods” and a timer, i.e. setInterval() within it. Will that work?

Hi Paul!

Could you provide your application id (with node.js project)
for a full investigation on our side?
Regards,
Kate.

Hi Kate,

I will take another look tonight and break it down. If I find an issue, we can go through a detailed look.

Thanks
Paul

Restrictions apply only to the time of execution, memory usage and access to external hosts.

You may get 504 response if your script doesn’t return any response in allowed time (which is 5 seconds for free plan).