Project specific dependencies

When using Node-RED project, I found that the project folder under userDir also has a package.json file.

When I add the dependency to the project from the editor, this file is also updated with the dependency.

However, such dependencies do not seem to be used as there is no node_modules under that specific project.

Is this a feature or a bug?

Like, do we target project specific dependencies - the dependencies/modules that are only loaded for a specific project (to be installed at projects//node_modules), or all projects share the runtime's dependencies (under userDir/node_modules)?

Thanks

The only nodes that get loaded are those found in userDir/node_modules. This is managed by userDir/package.json. For a flow to run, whether its a standalone flow or a Project, all of its dependencies must be installed there.

A project uses its own package.json to record what modules it depends on. This means if you share the project with another user, they will know what additional modules it requires. When they get installed, they are still installed in userDir/node_modules with all of the other runtime modules.

It also means, with a couple small changes to your package file, you can git clone a project, run npm install and then npm start and your flows will be running. This idea of making a project a standalone, deployable application is one of the key use cases for projects.

There's more work to be done to streamline some of this workflow - but in absence of anyone else contributing to make these improvements, they are sat behind lots of other higher priority items in the roadmap.

2 Likes

@knolleary, could you be a bit more specific? What changes are needed in the package file(s)? Is that userDir/package.json, the project package.json or both? I have a project running on my development machine that I would like to move to a production machine where I would rather run it on its own, not as a project. Will that complicate things?

Related: is the project feature still considered beta? Is the file structure under userDir/projects likely to change? Please feel free to tell me that this is all in the documentation somewhere that I missed.

Hi @drmibell

The changes are all in the projects own package.json. You need to add two things:

  1. add node-red as a dependency so it gets installed along side the project
  2. add a start command to run it

This blog post covers the details (although covers a lot more besides) - https://medium.com/@knolleary/creating-a-node-red-deployment-pipeline-to-ibm-cloud-9a8e9d5113de#65bd

1 Like

Thanks! Thanks! (Post must be at least 9 characters. Haven't we been here before?)

The procedure is nice for exporting a project, as a standalone and atomic package. I have been testing the procedure I would follow if I wanted to reuse my project in another machine.
But I have encountered two issues that I have not managed to fix:

  • I want to export also my settings.js. In such case, I have to modify it so that projects are disabled: if they are enabled, it tries to install nodes and look for flows file in ./projects/projectname. This is not a real problem, because maybe it is not a good practice to consider settings.js as being part of the project

  • As the credentials are encripted (I configured my project in that way, perhaps it is not the best practice), when deploying the project, credentials cannot be unencrypted, and I have not found the way of providing the secret credential: I have tried editing credentialSecret property in settings.js. Perhaps I should add it to the newly created .config.json, but in such case, it should be in the 'projects' section, but as I have pointed to in my first issue, I should not consider there are projects in this deployment

In the end,I am in a mess trying to know the best way to export my project in the cleanest way. Thanks a lot

For that reason I do not use the projects feature, I put the whole .node-red folder under git control and do it manually. Then I just have to git clone to deploy it.

Hi @peret2000

Current the settings file is not included in the project. We don't currently have a good way for a project to provide custom settings that can be overridden when the project is loaded without a full restart of the runtime.

It absolutely is the best practice to encrypt your credentials.

How are you deploying the project? Setting credentialSecret in the settings file is the right way to do and works well for me - see the blog post I linked to in the thread above.

Hi @knolleary,
You are very right. I have understood the possible places where the secret for credentials can be found, and it finally worked, in settings.js. Probably I did not write the property correctly.
So, it is working fine.

I have been trying to get that the cloned nodered instance (created just clonning from git a project and preparing it with 'npm install' and the 'npm start') could be managed as a project, but it has not been possible. Nodered always try to locate projects under ./projects directory.

It would be nice to be able to configure nodered so that the project iitself was located at the ./ directory

A workaroud I have found (not very smart) is:

  • Create an ampty package.json, with only a dependency to node-red
  • Run npm install, so that nodered and all its dependent modules can be installed
  • Configure settings.js so that projects are enabled (maybe first running 'npm start' to create a default settings.js)
  • Run 'npm start' and from the GUI configure the project, as that is the first pop up it shows