Solved: About syntax errors and good debugging practices

UPDATE: I solved the problem using online syntax checker at https://esprima.org/demo/validate.html I'm stuck with tmux and the right mouse button. But I would be glad if anyone who reads this message still can share a document or page about the good debugging practices I mentioned in the second paragraph.

I probably made a typo somewhere. But although I have repeatedly inspect it, I could not find the location of the parentheses error. Node-RED does not help me with this. My browser's debugger points to red.js but doesn't provide a hint about my local code. There is no output in node-red-log. I uploaded the latest version of the node which I developed to the (faulty) repository. Can someone take the time and check? Thanks :pensive:

I just met Node.js and developed a few nodes to experiment with. What I see is that I find it very difficult to debug and report. I generally benefit from node.log and consol.log. My log level is set to debug (settings.js). I follow the browser's console. This much. I have not been able to overcome this problem I am currently experiencing with these methods. It is also sufficient if you can enlighten me about what are good practices for debugging (other than what I mentioned above). I will surely locate the current error.

My node: https://github.com/enseitankado/node-red-contrib-ss963-driver

My settings.js:

    logging: {
        // Only console logging is currently supported
        console: {
            // Level of logging to be recorded. Options are:
            // fatal - only those errors which make the application unusable should be recorded
            // error - record errors which are deemed fatal for a particular request + fatal errors
            // warn - record problems which are non fatal + errors + fatal errors
            // info - record information about the general running of the application + warn + error + fatal errors
            // debug - record information which is more verbose than info + info + warn + error + fatal errors
            // trace - record very detailed logging + debug + info + warn + error + fatal errors
            // off - turn off all logging (doesn't affect metrics or audit)
            level: "debug",
            // Whether or not to include metric events in the log output
            metrics: false,
            // Whether or not to include audit events in the log output
            audit: false
        }
    },

node-red-log output:

17 Jun 06:02:51 - [info] Settings file  : /home/pi/.node-red/settings.js
17 Jun 06:02:51 - [info] Context store  : 'default' [module=localfilesystem]
17 Jun 06:02:51 - [info] User directory : /home/pi/.node-red
17 Jun 06:02:51 - [warn] Projects disabled : editorTheme.projects.enabled=false
17 Jun 06:02:51 - [info] Flows file     : /home/pi/.node-red/flows_raspberrypi.json
17 Jun 06:02:51 - [info] Server now running at http://127.0.0.1:1880/
17 Jun 06:02:51 - [debug] loaded flow revision: d039ad5fb31847b9ad0f9bb4d6708099
17 Jun 06:02:51 - [debug] red/runtime/nodes/credentials.load : no user key present
17 Jun 06:02:51 - [debug] red/runtime/nodes/credentials.load : using default key
17 Jun 06:02:51 - [debug] red/runtime/nodes/credentials.load : keyType=system
17 Jun 06:02:51 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
17 Jun 06:02:51 - [info] Starting flows
17 Jun 06:02:51 - [debug] red/nodes/flows.start : starting flow : global
17 Jun 06:02:51 - [debug] red/nodes/flows.start : starting flow : e0f91692.9ca4
17 Jun 06:02:51 - [debug] red/nodes/flows.start : not starting disabled flow : 85db3bb9.799208
17 Jun 06:02:51 - [info] Started flows
^C

Hi Ă–zgĂĽr,

Welcome to this forum!
When I paste the javascript code of your .html file in jshint.com, then you see this:

So when I follow the directions on the right pane, you should need to change it to this:

				var newConfigJSON = {
                	PORT_COUNT: $("#node-input-portCount").val(),
                    LATCH_PIN: $("#node-input-latchPin").val(),
                    LATCH_DELAY: $("#node-input-latchDelay").val(),
                    SPEED: $("#node-input-speed").val(),
          LOOP_DELAY_US: $("#node-input-loopDelayUs").val() }
                node.log("testtttt");

Then the syntax errors are solved.
Bart

1 Like

BTW in your node-red-log output you will only see the server side syntax errors, i.e. the syntax errors in your .js file. In the browser console log (like in your screenshot), you will see the client side syntax errors. I.e. the javascript in your .html file.

Had overlooked that you already solved the syntax error yourself ...
BTW If you really want to start debugging (i.e. not just setting the log level to debug), then perhaps this might be an easy way to get started. I wrote that tutorial for a function node, but it also works for any other Node-RED node ...

1 Like

A few articles have been written about debugging with Node-RED, I think there is one on my blog.

Most of the time, debugging involves simply copious amounts of logging statements. I tend to use console.log for temporary outputs - leaving the node-red log for things I probably want to leave in place longer-term.

I also tend to include some standard info about where in my node the output is coming from. Such as this simple example from uibuilder:

console.log('[uiblogin] Validation Errors: ', errors)

or this slightly more complex example:

console.log('[uibuilder:socket.on.control] Use Security _auth: ', msg._auth, `. Node ID: ${node.id}`)

For the occasional need that goes beyond that, I use VScode's debugging features by starting up Node-RED with a custom npm start script:

  "scripts": {
    "start": "pm2 start ecosystem.config.js",
    "start4": "nodemon --ext js,html node_modules/node-red/red.js --userDir ./data",
    "start2": "set DEBUG=express:* & nodemon node_modules/node-red/red.js --userDir ./data",
    "start3": "node node_modules/node-red/red.js --userDir ./data",
    "doctor": "clinic doctor -- node node_modules/node-red/red.js --userDir ./data",
    "bubble": "clinic bubbleprof -- node node_modules/node-red/red.js --userDir ./data",
    "inspect": "node --inspect node_modules/node-red/red.js --userDir ./data",

The last one attaches an inspector which can be used from within VScode. You need to remember to put a break statement in your code though otherwise the way that Node-RED starts up, you wont see much in the debugger.

Node.js isn't that easy to debug itself and the complexity of Node-RED as a platform makes that even harder because of the way everything links together. But once you have the hang of it, it isn't too hard.

1 Like

BartButenaers, TotallyInformation The information you provided was very useful for a beginner like me. I have not encountered these methods before. Thank you for your help. :+1:

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.