TLDR Summary: When embedding node-red in an existing app, I'm hoping there's a way to "require" the app's modules from the .js files of custom nodes that I write.
Details:
I have an existing node.js express app (serving some JSON rest apis).
I successfully embedded node-red into that app following the docs here:
https://nodered.org/docs/user-guide/runtime/embedding
And I've successfully created a standalone custom node, i.e. with it's own package.json in the form that could be published all by itself which I assume is the normal way.
But my node app has business logic in modules that I need to require and use from the js file for a suite of custom nodes that would be specific to my project.
But those modules aren't separately published they're just under src of the node app.
And so I can't do "requires" for that code from a custom node coded the typical way as a separate standalone package right?
My question: now that I've embedded node-red in this app, can I create my custom nodes simply as files under the src of the app's package instead of being separate standalone packages?
And doing that would it mean the js files for those custom nodes would be able to do requires of my "business logic" modules there?
Update:
I've figured out something that works which is:
a. In my main file where I embed node-red I point userDir at my project root directory i.e.:
const settings = {
// we are pointing userDir at our project root so that our custom nodes
// can see the same node_modules as our project
userDir: `${console.log(__dirname)}/..`,
...
}
b. I add all the node-red node dependencies that were in ~/node-red/package.json into my project's package.json.
c. I put my custom nodes as loose js/html files in the "nodes" directory (which is simply under the project root directory because of a)
Now my only concern is about "c" from the node-red docs about the "nodes" directory:
https://nodered.org/docs/user-guide/runtime/adding-nodes#installing-individual-node-files
It says "this is only recommended for development purposes".
Does anybody know why it's only recommended for development?
Is it like a security risk somehow?
(or maybe it's just there's no easy way to publish and share custom nodes that way - in that case maybe I'm ok as I don't/can't share my custom nodes they are specific to my project)