Node custom scripting error

Hello everyone,
I’m using bitnami vers. DreamFactory,

Versions ; Admin Application Version: 2.1.3 and DreamFactory Version: 2.1.0

I follow the node.js math tutorial (node installation complete and .env file edited as you describe)

When i try to run script from test_rest_html, generate following error below;

{
“error”: {
“context”: null,
“message”: “Array to string conversion”,
“code”: 500,
“trace”: [
“0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, ‘Array to string…’, ‘/opt/dreamfacto…’, 124, Array)”,
“1 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Services/Script.php(124): strval(Array)”,
“2 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Components/RestHandler.php(173): DreamFactory\Core\Services\Script->processRequest()”,
“3 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Services/BaseRestService.php(65): DreamFactory\Core\Components\RestHandler->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), NULL)”,
“4 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/vendor/dreamfactory/df-core/src/Utility/ServiceHandler.php(57): DreamFactory\Core\Services\BaseRestService->handleRequest(Object(DreamFactory\Core\Utility\ServiceRequest), NULL)”,
“5 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17669): DreamFactory\Core\Utility\ServiceHandler::processRequest(‘v2’, ‘math’, NULL)”,
“6 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17634): DreamFactory\Http\Controllers\RestController->handleService(‘v2’, ‘math’, NULL)”,
“7 [internal function]: DreamFactory\Http\Controllers\RestController->handleGET(‘v2’, ‘math’)”,
“8 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8873): call_user_func_array(Array, Array)”,
“9 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8942): Illuminate\Routing\Controller->callAction(‘handleGET’, Array)”,
“10 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8922): Illuminate\Routing\ControllerDispatcher->call(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), ‘handleGET’)”,
“11 [internal function]: Illuminate\Routing\ControllerDispatcher->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,
“12 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9593): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,
“13 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17817): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“14 [internal function]: DreamFactory\Http\Middleware\AccessCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“15 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“16 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“17 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9575): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,
“18 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8923): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,
“19 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(8908): Illuminate\Routing\ControllerDispatcher->callWithinStack(Object(DreamFactory\Http\Controllers\RestController), Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘handleGET’)”,
“20 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7862): Illuminate\Routing\ControllerDispatcher->dispatch(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request), ‘DreamFactory\\Ht…’, ‘handleGET’)”,
“21 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7833): Illuminate\Routing\Route->runWithCustomDispatcher(Object(Illuminate\Http\Request))”,
“22 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7486): Illuminate\Routing\Route->run(Object(Illuminate\Http\Request))”,
“23 [internal function]: Illuminate\Routing\Router->Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))”,
“24 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9593): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,
“25 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“26 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9575): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,
“27 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7487): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,
“28 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7475): Illuminate\Routing\Router->runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))”,
“29 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(7460): Illuminate\Routing\Router->dispatchToRoute(Object(Illuminate\Http\Request))”,
“30 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2307): Illuminate\Routing\Router->dispatch(Object(Illuminate\Http\Request))”,
“31 [internal function]: Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))”,
“32 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9593): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,
“33 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/app/Http/Middleware/AuthCheck.php(170): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“34 [internal function]: DreamFactory\Http\Middleware\AuthCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“35 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“36 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/vendor/barryvdh/laravel-cors/src/HandleCors.php(34): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“37 [internal function]: Barryvdh\Cors\HandleCors->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“38 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“39 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(17909): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“40 [internal function]: DreamFactory\Http\Middleware\FirstUserCheck->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“41 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“42 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12961): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“43 [internal function]: Illuminate\View\Middleware\ShareErrorsFromSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“44 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“45 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(11555): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“46 [internal function]: Illuminate\Session\Middleware\StartSession->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“47 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“48 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12698): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“49 [internal function]: Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“50 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“51 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(12635): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“52 [internal function]: Illuminate\Cookie\Middleware\EncryptCookies->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“53 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“54 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2982): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“55 [internal function]: Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode->handle(Object(Illuminate\Http\Request), Object(Closure))”,
“56 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9585): call_user_func_array(Array, Array)”,
“57 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))”,
“58 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(9575): call_user_func(Object(Closure), Object(Illuminate\Http\Request))”,
“59 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2254): Illuminate\Pipeline\Pipeline->then(Object(Closure))”,
“60 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/bootstrap/cache/compiled.php(2237): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter(Object(Illuminate\Http\Request))”,
“61 /opt/dreamfactory-2.1.0-4/apps/dreamfactory/htdocs/public/index.php(53): Illuminate\Foundation\Http\Kernel->handle(Object(Illuminate\Http\Request))”,
“62 {main}”
]
}
}

How can i solve this?

It looks like there is some problem in your script. Please share your code so we can have a better idea of what is going on.

There were some significant bugs with Node in 2.1.0 – resolved in 2.1.1.
I don’t know off the top of my head if this was one of them, but it might be worth upgrading to see.

I used the following tutorial : https://wiki.dreamfactory.com/DreamFactory/Tutorials/Node_custom_scripting_service_math

I upgrade to 2.1.1 and problem solved. Thank you @formerstaff

1 Like

Hello folks,
I have DF installed in windows with Admin Application Version: 2.1.3 ,DreamFactory Version: 2.1.0

  1. I added custom server side script using the example - math node.js script by following exact steps provided in the blog https://blog.dreamfactory.com/server-side-scripting-with-node.js

  2. Added swagger service definition with the help of this blog…
    https://blog.dreamfactory.com/put-some-swagger-in-your-dreamfactory-custom-scripting-services

  3. updated DF_NODEJS_PATH in .env file to point to node installables

  4. node.js version is v 4.5.0

When trying to test using swagger, i am getting nulls as result.

Request URL: localhost/api/v2/math/add?n1=10&n2=10
Response Body : ""
Response Code:200

Checked the log and it has following messages -

[2016-08-30 03:28:58] local.ERROR: * Script did not return an array:
[2016-08-30 03:28:58] local.DEBUG: Service event: math.get.post_process
[2016-08-30 03:29:08] local.DEBUG: Service event: math.get.pre_process
[2016-08-30 03:29:09] local.ERROR: Exception executing javascript: Node script returned with error code: 1

Please let me know what is that i am missing… causing this error to appear…

SS

can you navigate to the htdocs folder and do
npm install lodash

You may need to provide the full path to the npm executable

Hi There

Could you let me know where exactly is the htdocs folder. I could not find it?