Node Github template

I created a template repo on Github you can use to quickly start a new node:

It's not fancy or anything but could be useful, it integrates a sample test too.
Let me know what you think !

Hi Nathanaël,

Must admin that I like more structure to my packages. I always put my nodes into a nodes folder. It is true that uibuilder is a little on the extreme side but this is the top-level structure for it:

node_modules wouldn't be in git of course. And templates and front-end are quite specific to uibuilder. You might not want the typedefs and .d.ts files either. But I usually end up with bin, docs, examples, nodes, tests. I always include a, a LICENSE, generally a and sometimes a file.

I also prefer a more strongly structured .js file with at least sections for overall setup, a nodeInstance function that is consumed by the registerType (I always use the same function name rather than calling it after the node since I find that unnecessarily specific and distracting). nodeInstance will contain a nodeInputHandler function that is consumed as node.on('input', nodeInputHandler) and also a node.on('close', function(removed,done) {...} so that I don't forget it if I need it.

I also find it helpful to have a configuration node in my standard template because I can never remember how to do that without lots of reading :slight_smile:

My html file uses the newer <script type="text/html" data-template-name="uibuilder"> and <script type="text/html" data-help-name="uibuilder"> sections rather than using text/x-red which editors really don't like. Also, my front-end javascript is wrapped in an IIFE because lack of that really caused me some VERY hard to track down bugs in the past.

;(function () {
    // all the code - a leading ; because I don't use trailing ;s all over the place

I also make use of extensive 'regions' comments along with lots of JSDoc to help eliminate the silly mistakes I'm prone to making. Regions let you fold up arbitrary areas of code in the better code editors.

Thanks ! I'll update it with some of your suggestions.
I wanted to keep my template simple as I usually add more folders if the node gets more complex over time.

Certainly nobody ever called my code or designs "simple" :grinning:

I decided that I don't like thinking about things if I don't have to and so I'd rather start with everything in place up front. I can always delete if things get too messy but honestly, I nearly always end up with everything anyway.

Thanks for sharing

1 Like

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