I tried with following code in .js file directly .
msg.payload = msg.payload.toLowerCase();
return msg;
It failed to add 1 to output in generated code .
I tried with exported json with output set to 1 ,but it did not worked at all even though it generated code without output set.
It will good if we can keep a sample code to pass in the documentation .
My NR version
26 Feb 17:22:06 - [info] Node-RED version: v1.0.3
26 Feb 17:22:06 - [info] Node.js version: v12.16.1
26 Feb 17:22:06 - [info] Windows_NT 6.3.9600 x64 LE
Node version is v12.16.1
Also without passing --name in command it does not work at all ,ie it throw error as I mentioned before.
Following doc says to export as .js ,I was not able to export as .js it comes as .json .
https://github.com/node-red/node-red-nodegen
I think the module is not written for latest NR
Can I use a code which need another module using require and generate a node?.
Thank you for your support.
If you create your node manually (as per nodes - https://nodered.org/docs/creating-nodes/first-node) you can add required packages to your package.json.
nodegen works with latest Node-RED. When you say you are adding code to .js file directly - that is not the way it is supposed to work. As previously point out - you create a function node in Node-RED then save it to the library (book icon on the node config page) - then point nodegen at that file in the library.
the two methods of creating nodes cannot be mixed. (At least not easily).
@josekavunkal this post from @zenofmud showed how you save the Function node to your library to get the file that nodegen works with: Is there a simple way to generate a custom node from .js file
You do not export the whole node. You do not hand-create a .js file, unless you also add the extra meta-data lines that are shown in the post I link to.
I do think that nodegen could be updated to work with the JSON export of a Function node, because it will contain all of the required information. But that is a separate discussion.
Everything worked .
Thank you so much . .
It will be helpful if we have a documentation with sample code and UI screen shots .
I was using Node-red for many years ,but did not realize that there is a book icon to save to .js .
My next step is to add an a require statement and use code from another library .
Thanks Again,
Jose