Hello guys, I'm trying to create my first node in Node-RED, but I haven't been successful so far.
I'm using the lower-case example from Node-RED.
The steps I'm following are the following:
1.-create folder in directory .node-red/node-modules/
2.-I'm creating the files package.json, lowercase.json, and lowercase.html.(In the package.json file, I'm defining the location of lowercase.json)
3.- Restart node-red
These steps haven't worked for me, what can I do? Could you help me with an example or point out where I'm going wrong or skipping?
No, you can't do it there.
Node-RED is a node.js app. So you should generally follow the development process for a node.js module, that is then packaged via npmjs.org and so available to Node-RED.
To develop, the best workflow is to create a new GitHub repository. Clone it to your local development machine. Go into the folder you cloned to and do
npm init -y to give yourself a package.json file.
Then you should be able to install the module into node-red simply by switching to your userDir folder (e.g.
~/.node-red/) and doing
npm install /path/to/my/clone/folder.
Finally restart node-red.
To make changes to the code, all you then have to do is save the file and restart node-red. For changes to the html file, you will also have to reload the Editor page.
You can use something like PM2 to run node red on your dev device and configure it with a watch config so that node-red restarts when an appropriate file changes. That saves some effort.
To use the lowercase node as an example, do the same but copy in the 3 files before restarting Node-RED. Or copy them into your original GitHub repo before cloning.
And to keep things organised: I have moved this to the Developing Nodes category
I think I understood something. But could you explain it a little more detailed.
I create my directory in the path /root/myexample. Then in this directory, I initialize a git and use npm init to create the package.json file.
And Then I create my lower-case.html and js files (/root/myexample).
But then how do I install it in Node-Red?
I understand that you tell me that I should use "npm install /root/myexample" inside folder .node-red/node_module ?
Do it within your
Im going to assume you work in
npm install <root DIR of your poject> <- the Dir that your package.json is in
npm install /root/development-projects/kick-ass-node
This wil install into
/root/.node-red/node_modules <- no need (In fact, Dont) be in the node_modules dir when running install
Yes, but copy over the package.json as well since you need the node-red entries from it.
npm install /root/myexample
@TotallyInformation ... I also am in the process of writing my own node and have one question on the setup. I read on one of the NR doc pages that we should exclude the "node-red" section on the package.json file until we are ready to release it to the public. Could you provide some clarity on if that is true or not?
Not the node-red section, don't add a "node-red" keyword. That means that if you publish it, it won't appear in the node-red palette manager or the flows site until you are ready for it to be publicly usable. You can still get people to test it by installing from the command line.
@TotallyInformation ... ah ok, much thanks for that clarification
Also note that there is no need to publish it on npm before it is ready for general use. If you are not publishing it on npm then you can include the keyword immediately.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.