Deploy event handler problem

Hey guys, backendless has enough docs regarding Business logic with event handlers but still i i have event handler which is not working. So here is my scene,

I have event handler “after” on “Data Tables”. I downloaded code, edited it and working perfectly when i run

npm run debug

And i can see it in “Debug” tab. When i deployed it using

npm run deploy

It deployed successfully and i can see it in “production” tab. But when my data table gets new row, my custom code that is deployed is not working. But it is working in “debug” mode.
I searched a lot but still not able to find solution. What are the things i am doing wrong?
Thanks.

Hi Daxxel

Please go through Troubleshooting guide steps and let us know if that doesn’t help

Sure. Will let you know. Thanks.

How can i install request module in node. Because i am getting this error.

Error: Cannot find module 'request'

Before deploying, you should install it with --save command line argument.
This way the package will appear in your dependencies section of your package.json file, and will be deployed to the Cloud along with your business logic scripts

npm i request --save

Thanks it worked. The error solved. But there is one another issue.

I have GET REQUEST code like this

Backendless.ServerCode.Persistence.afterCreate('TABLE', function(req, res) {
    // get request code
}

But in debug my get request worked but in deploy it is not working. How can i solve?

Here is full code, this displays “GET request successful” in debug mode but not in deploy code.


Backendless.ServerCode.Persistence.afterCreate('TABLE', function(req, res) {
	request.get({
		headers: {
			"application-id": "APP_ID",
			"secret-key": "SEC_KEY",
			"application-type": "REST"
		},
		url: "GET_URL"
	}, function(error, response, body){
		console.log("GET request successful");
	});
}, true);
	

See in the Troubleshooting guide :

===
If you see that the Business Logic execution was interrupted (for example, you see some of the console.log messages, but don’t see the others), that means that you have some undeclared asynchronous IO operations, which were interrupted by the CodeRunner. This happens when asynchronous operations started by your code are not properly returned to CodeRunner. Business logic method must return a Promise to CodeRunner which should be resolved only when all asynchronous jobs are finished.
This is explained in the Sync vs Async Article.

So, in your case, the code should look like this :

return new Promise((resolve, reject) => {
 request.get({..}, function(error, response, body) {
 if (error) {
 reject(error)
 } else {
 console.log("GET request successful");
 }
 })
})

It worked perfectly but got another error.

2016-09-26 13:02:59,517 | SERVER_CODE | ERROR | Error: Task execution is aborted due to timeout
    at null._onTimeout (/var/lib/backendless/nodejscoderunner/lib/util/promise.js:71:29)
    at Timer.listOnTimeout (timers.js:92:15)

Hi Daxeel

Just added several additional cases (including yours) into the Troubleshooting guide
Please take a look