I have created a custom node .js and .html file along with a package.json empty file.
I execute npm init in the directory that contains the file and it creates the package.json as required.
Next I run npm install in the same directory and it runs, no errors indicated.
Next I shutdown Node Red and then restart it.
I refresh my Node Red page in the browser, but my custom node does not show up!
Also, I am running my Node Red on W10.
Any suggestions?
do you have the nodes registered in the package.json as per docs? https://nodered.org/docs/creating-nodes/first-node#package-json
In what directory have you done all of that?
My directory is .node-red\nodes\ss-modify-point-value
my package.json
{
"name": "ss-modify-point-value",
"version": "1.0.0",
"description": "",
"main": "ss-modify-point-value.js",
"scripts": {
"test": "echo "Error: no test specified" && exit 1"
},
"author": "",
"license": "ISC",
"node-red": {
"nodes": {
"ss-modify-point-value": "ss-modify-point-value.js"
}
}
}
Does this help?
Hi @tcontrada
as a side note, when sharing code of any sort, it helps to format it properly - this post explains how/why: How to share code or flow json
The .node-red/nodes
directory is used to load local nodes that are not packaged as a module - so the package.json is ignored and it will load any .js/.html file pair it can find.
Are there any error messages in the log when you start Node-RED related to your node?
That's the funny thing, is that there are no errors in the Node Red console when starting. Here is the start message: There is a Warning message, but not sure if it's important?
Welcome to Node-RED
21 Feb 17:36:52 - [info] Node-RED version: v0.19.5
21 Feb 17:36:52 - [info] Node.js version: v10.13.0
21 Feb 17:36:52 - [info] Windows_NT 10.0.17134 x64 LE
21 Feb 17:36:53 - [info] Loading palette nodes
21 Feb 17:36:56 - [info] Dashboard version 2.13.2 started at /ui
21 Feb 17:36:56 - [warn] rpi-gpio : Raspberry Pi specific node set inactive
21 Feb 17:36:57 - [warn] ------------------------------------------------------
21 Feb 17:36:57 - [warn] [node-red/tail] Not currently supported on Windows.
21 Feb 17:36:57 - [warn] [node-red/ss-modify-point-value] Type already registered
21 Feb 17:36:57 - [warn] [ss-modify-point-value/ss-modify-point-value] Type already registered
21 Feb 17:36:57 - [warn] ------------------------------------------------------
21 Feb 17:36:57 - [info] Settings file : \Users\tcontrada.node-red\settings.js
21 Feb 17:36:57 - [info] Context store : 'default' [module=memory]
21 Feb 17:36:57 - [info] User directory : \Users\tcontrada.node-red
21 Feb 17:36:57 - [warn] Projects disabled : editorTheme.projects.enabled=false
21 Feb 17:36:57 - [info] Flows file : \Users\tcontrada.node-red\flows_TCONTRADALABLT.json
21 Feb 17:36:57 - [info] Server now running at http://127.0.0.1:1880/
21 Feb 17:36:57 - [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.
21 Feb 17:36:57 - [info] Starting flows
21 Feb 17:36:57 - [info] Started flows
21 Feb 17:36:57 - [info] serial port COM5 opened at 115200 baud 8N1
21 Feb 17:36:57 - [info] serial port COM16 opened at 115200 baud 8N1
21 Feb 17:36:57 - [info] serial port COM13 opened at 115200 baud 8N1
21 Feb 17:36:57 - [info] serial port COM14 opened at 115200 baud 8N1
No, those warnings are exactly why your nodes don't show up. It could be because you have the package.json file there - as I said, you shouldn't add one under the nodes
directory.
More commonly, you'd use npm link
or similar to 'install' the nodes under .node-red/node_modules
as if they were 'real' node modules.
Hi Nick,
At this point I am really confused. I have placed my .js and .html files in .node-red\nodes\ss-modify-point-value folder. I deleted the files from the .node-red\node_modules folder.
So as you say Node Red should pick up my files in the .node-red\nodes\ss-modify-point-value folder.
But, I am still getting a Warning message saying [warn] [node-red/ss-modify-point-value] Type already registered.
What should I try now?
Thanks...
Have a look in the file .node-red/.config.json
for any mention of your nodes. That will tell you where the runtime has found them and may help clarify it for you.
As I mentioned before, I'd recommend packaging them as proper node modules and using npm link
(as described in the docs) to install them under .node-red/node_modules
and not just place the files under ~/.node-red/nodes
.
So use this method?
On Windows with older versions of npm, use mklink
instead:
cd C:\Users\my_name\.node_red
mklink /D node_modules\node-red-contrib-example-lower-case C:\Users\my_name\Documents\GitHub\node-red-contrib-example-lower-case
Where do I put my .js and .html files, in node_modules/my-custom-node ?
another way is to put your .js and .html AND package.json (with the node-red entry specifying your nodes) into a folder, lets say /home/user/nodeBla/my-custom-node
Then you goto your node-red user directory and run npm install /home/user/nodeBla/my-custom-node
This will do something similar to npm link, but a little bit easier to work with. Refer to the npm documentation for details.
Oh, I just read that you are using an old version of npm, it could be that the method I described does not work then....
More issues:
If I try to use link I get the following message:
'link' is not recognized as an internal or external command,
operable program or batch file.
If I try to use mklink I get the following message:
You do not have sufficient privilege to perform this operation.
I do have admin rights on this PC as well.
So now what?
I also always do it the way @cinhcet suggests ... manually use npm install to point to a directory where I have a .js .html and package.json files (that is in my development directory away from main Node-RED install tree)
2 Likes
I am trying very hard to make this work. What bothers me is a month ago I was able to create custom nodes without difficulty, but now, for some reason I am having issues.
So when I run the npm install I get the following output:
npm WARN JSON.parse Failed to parse json
npm WARN JSON.parse Unexpected end of JSON input while parsing near ''
+ red-contrib-modify-point-value@1.0.0
added 3 packages and updated 1 package in 3.47s
When I restart Node Red I get the following Warning:
[warn] [red-contrib-modify-point-value/ss-modify-point-value] Type already registered
The node does not show up on the palette.
show your package.json here. Please use tripple backticks as described here How to share code or flow json
{
"name": "red-contrib-modify-point-value",
"version": "1.0.0",
"description": "",
"main": "ss-modify-point-value.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"node-red" : {
"nodes": {
"ss-modify-point-value": "ss-modify-point-value.js"
}
},
"author": "",
"license": "ISC"
}