Debug app code

I started with developing an app for homey and it goes quite well. I’m using vscode for the code writing and installed nodejs and the homey cli. I’m able to build and app with a device and driver which now runs on my Homey. I can see some log items etc appearing in the terminal which is all fine. I’m quite a newbie with developing but I do know the basics. But I’m missing the part of debugging code, is it possible to step into the code with breakpoints while running the app in homey? If so, how can it be done?

1 Like

You can add the following line of code to the top of app.js:

require('inspector').open(9229, '')

That will start the V8 inspector when the app gets started, and you can interact with it from a regular Chrome browser (open chrome://inspect/ and it should be able to find it).

I have no idea if/how this works in combination with VScode. Also, make sure to remove that line from the code once you’re ready to publish the app.


I use these 4 lines of code (app.js) in each of my apps, so you can debug in VScode (remote) and then you don’t have any problems publishing the app


// Start debuger
if (process.env.DEBUG === “1”) {
require(“inspector”).open(9229, “”, false);
//require(“inspector”).open(9229, “”, true);


Could you explain more about setting up VSCode?

This is what I have tried:
I have added require('inspector').open(9222, '')
I have selected the configuration as Node.js: Attach to remote program,
I entered the address as and set the port to 9222
but when I run the debugger it eventually comes up with:

1 Like

launch.json settings

			"type": "node",
			"request": "attach",
			"name": "Attach to Homey",
			"address": "192.xx.xx.xx",        <- homey ip-address
			"port": 9229,
			"localRoot": "${workspaceFolder}",
			"remoteRoot": "/"

Perfect, thank you.
Just one small note about

This has smart quotes so it can’t be just be copied and pasted. So for anyone that wants to use it, replace all the “ with ’

If only I had know all this before it would have saved me so much time.

So a massive thanks to @robertklep and @cgHome

1 Like

Never mind, I use " :stuck_out_tongue_winking_eye:

The editor will automatically replace any regular quotes with their “smart” counterparts if used in regular text.

For pasting pieces of code, use the “Preformatted text” button:


1 Like

I’m not sure if I was clear, but what I meant was I copied and pasted the example code into my file using VSCode, but when I ran the app it crashed because it didn’t understand the " characters that were pasted in. After I replaced all the " with ’ it works fine. Maybe it is a strange quirk with the way the text is placed in the clipboard when copied from the forum.
It took me a while to work out what the problem was as the error message in the crash just said the option was invalid.

1 Like

Hi All, thank for the information, it helps a lot.

It appears that I’m able to attache the remote debugger from VS code. I changed the launch.json code in the directory of the app to the code above and pressed F5 with node.js and after that I run the app with ‘homey app run’, I got message that the debugger is attched etc and can also see the callstack. But when I set breakpoints in the explorer view de dots become grey and I’m not able to step into the code. What am I missing here? Sorry for the noob questions :slight_smile:

Nevermind, when posted this I saw the problem, I replace the compleet json file instead of adding the setting. It now works.

Edit the json.
Open the run tab
Run the “Attach to homey”
start the app: “homey run app”

Thanks all!

Great help, but when I try to start the app “homey run app” from inside VScode it tells me “cannot be loaded because running scripts is disabled on this system”… what am I doing wrong?

It should be ‘homey app run’. Simple typo by op.

I read about this in the Slack #Developers channel a while back.
I improved upon it and it can now launch the Homey app and attach the debugger automatically:

Only thing I’m still hoping to achieve is having the ‘attach’ tab open automatically. Best thing for now is to wait until the floating debugger bar (The thing they complain about here) shows a drop-down menu. Then you can switch in the debugger tab to the ‘attach’ tab.

1 Like