Import local javascript file to my custom node red node

927 views
Skip to first unread message

Luka Špoljarić

unread,
Feb 10, 2017, 9:00:50 AM2/10/17
to Node-RED
Hello, 
Im having a lot of trouble getting acces to external local javasript files from within my custom node I made.
does anyone have any tips, and is it even possible?

Nick O'Leary

unread,
Feb 10, 2017, 9:12:40 AM2/10/17
to Node-RED Mailing List
Hi Luka,

do you mean in the runtime part of the node (provided by its .js file), or from within it's edit dialog in the editor (from the .html part)?

Nick

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
To view this discussion on the web, visit https://groups.google.com/d/msgid/node-red/43183d12-37de-48f4-a036-6083155cc448%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Luka Špoljarić

unread,
Feb 10, 2017, 9:17:18 AM2/10/17
to Node-RED
Hi Nick
from within the .js file, the main reason i want to do that is, i have several similar nodes, that will need to use same functions and would like that function to be centralized in a separate .js file.

Luka


On Friday, February 10, 2017 at 3:12:40 PM UTC+1, Nick O'Leary wrote:
Hi Luka,

do you mean in the runtime part of the node (provided by its .js file), or from within it's edit dialog in the editor (from the .html part)?

Nick
On 10 February 2017 at 14:00, Luka Špoljarić <spolja...@gmail.com> wrote:
Hello, 
Im having a lot of trouble getting acces to external local javasript files from within my custom node I made.
does anyone have any tips, and is it even possible?

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.

Nick O'Leary

unread,
Feb 10, 2017, 9:41:11 AM2/10/17
to Node-RED Mailing List
Ok, so what have you tried? I assume you are using the standard node.js require() method, giving it the path to the .js module you want to include?

Nick

To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Luka Špoljarić

unread,
Feb 10, 2017, 9:42:17 AM2/10/17
to node...@googlegroups.com
Thats exactly what im trying to do.

You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/_9QlC27T8c4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+unsubscribe@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

Nick O'Leary

unread,
Feb 10, 2017, 9:43:41 AM2/10/17
to Node-RED Mailing List
ok... without any more details on what you've tried, what errors you are hitting etc, I'm not sure what else to say.

Nick

Luka Špoljarić

unread,
Feb 10, 2017, 10:04:33 AM2/10/17
to Node-RED
Hi Nick sorry about last message, was typing from in a hurry phone and couldnt give you more details.
anyway
I am trying to reference to a .js file named "m2md.js" that is in the same directory as the node, and it is giving me error  "Error: Cannot find module './m2mdm.js'"

File structure
-- create-doctor/
   - create-doctor.html
   - create-doctor.js
   - m2mdm.js
 

code:
module.exports = function (RED) {
"use strict"
var m2mdm = require("./m2mdm.js"); // external js hook
function validateInput(node){
if(node.doctorID == ""){
return false;
}
return true;
}
function createDoctor(config){
var prefix = require("../../config.json").user + "_";
RED.nodes.createNode(this, config);
this.doctorID = config.doctorID;
var node = this;

this.on("input", function(msg){
if(validateInput(node)) {
msg.type = "doctor";
msg.operation = "create";
msg.entityData = {
'urn': prefix + node.doctorID,
'attributes': [{
"name": "type",
"value": "DOCTOR"
}]
};
node.send (msg);
}
else
this.error("Please input expected arguments: doctorID");

})
}
RED.nodes.registerType("create-doctor", createDoctor);
}

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to a topic in the Google Groups "Node-RED" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/node-red/_9QlC27T8c4/unsubscribe.
To unsubscribe from this group and all its topics, send an email to node-red+u...@googlegroups.com.

To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.

--
http://nodered.org
 
Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+u...@googlegroups.com.
To post to this group, send email to node...@googlegroups.com.
Visit this group at https://groups.google.com/group/node-red.
Reply all
Reply to author
Forward
0 new messages