New in developing Nodes

Hi the community,
I am trying to develop my own nodes (and I am not a dev) when I find exactly what I want in the repository.
The first one I created is one that allow me toretreive all the events between 2 dates / times from Google Calendar in a specific calendar (some exists, but are old, or I was not able to make them work). It is working well on my environnement, but I have no idea if it is properly done or not. How can I share it to have comments about it ?
Thanks
Regards

Welcome to the forums @fdecourt

And a thank you for contributing to the project.
If you have a Github account - upload your project to it, and share its repo link.

Thanks @marcus-j-davies. Here is the repo link, just uploaded : GitHub - fdecourt/node-red-contrib-google-calendar-events: Retreiving Calendar events from Google Calendar for NodeRed

Needed more work :wink:

Great! thanks

I dont use google for anything.
but just a few tips on the code itself.

  • Use off var
    I would try to switch to let - var is extremely dated and isn't suggested these days

    let : scoped, value can change
    const : scoped, value cannot change

    var can introduce some strange behaviour as it is not scoped, and can effect other variables with the same name, outside the code block

  • Let Node RED do the work for you in the oneditprepare and oneditsave

    $("#node-input-endDate").val(node.endDate);
    node.startDate = $("#node-input-startDate").val();
    
    // plus others
    

    You dont manually need to set the inputs, or set the config variables your self, the editor will load, and save them for you - providing the names are the same (and follow the correct name format)

  • Add on('close')
    This is recommended as it allows Node RED to be told when its safe to bring down the Node fully

    example:

    node.on('close', (removed, done) =>{
        // do tidy up
        // removed - deleted or just restarted
        done()
    })
    
  • Enhance the input, to allow complete and catch nodes to be supported

    example:

    node.on('input', async (msg, send, done) => {
        // do stuff
        try {
            msg.payload = {}
            send(msg)
            done()
        } catch (err) {
            done(new Error('It Broke'))
        }
    
    })
    
  • Protect your API endpoints

    example:

     RED.httpAdmin.get('/google-calendar/get-calendars', RED.auth.needsPermission('flows.write'), function(req, res){})
    

Just some things I spotted (I didn't use a fine toothed comb), overall - Nice work! :smiley:

3 Likes

@fdecourt - Please note the node naming protocol - Packaging : Node-RED

Packages should use a SCoped name - Such as @myScope/node- red-
sample. That can be under a user SCope or an organisation scope.
So probably better to change it before it gets published.

You could use something like @fdecourt/node-red-google-calendar-events (no need now for the contrib...)

Oh, and don't forget to add the repository section to your package, so users will know more about how it works, report issues, or even contribute.

2 Likes

Thanks @Paul-Reed , I will update it. it is just a very first draft (v0.0.1 ;-)... Just sharing it to have some comment on the direction I took ! it is working, but not clean enough to be used by other, yet.

Thanks a lot @marcus-j-davies. I will use your advices.

1 Like

Ok, I updated the code to, hopefully, make it better ! Is someone is ready to test, it will be nice :wink: :slight_smile:

I have one question. To initiate the connection to Google, I have a configuration node that allows entering the Client ID and Secret Key. The problem is that the first time I want to set it up, I must first input the information (Secret Key and ID), then save, then save the google-calendar-events node, then deploy, and finally return to the configuration of the google-calendar-config node, where I can start the authentication process. Even though this only needs to be done once, it is not very user-friendly. This likely happens because the nodes are not yet deployed, so the entire mechanism isn't in place. Is there a way to make things cleaner while maintaining a global configuration? Thank you for your help.