Use Github with Node-RED

Connecting Node-RED Projects with Git & GitHub (Version Control)

 

Yes, you can integrate your Node-RED projects with Git and GitHub for version control. However, it requires a bit of configuration both in Node-RED and GitHub. Below, I'll guide you through the setup process in different ways.

 

Enabling Node-RED "Projects" on Your Server

 

Before utilizing Git with Node-RED, you need to enable "Node-RED Projects."

Note: Enabling Node-RED Projects does not affect your existing nodes and flows. It simply adds version control functionality to your Node-RED environment, allowing you to better manage your projects with Git and GitHub.

Modifying the settings.js File:

Locate your Node-RED directory based on your operating system:

Windows: C:\Users\<windows-user>\.node-red

Mac: /Users/<mac-user>/.node-red

Linux: /home/<linux-user>/.node-red

 

If you're using Docker, find your node-red-data mount:

docker inspect <container-name> | grep -A 5 Mounts

 

In the .node-red directory, find the config.js file.

Uncomment the following lines and enable the projects variable:

 

editorTheme: {

    projects: {

        enabled: true

    }

}

 

Restart the Node-RED server after the change.

 

When you open Node-RED with "Projects" enabled for the first time, you'll see a pop-up window guiding you through the setup process.

 

Afbeelding met tekst, schermopname, scherm, Lettertype

Automatisch gegenereerde beschrijving

Create a new node-red project

1. To initiate a new Node-RED project, simply click on "Create Project." Rest assured, this action won't affect your existing flows or nodes.

2. Follow the prompt to set up your Git username and email. Once completed, click "Next" to proceed with project creation.

Afbeelding met tekst, schermopname, Lettertype, nummer

Automatisch gegenereerde beschrijving

 

3. Enter your desired Node-RED project name and description. Note that it doesn't need to match your GitHub repository name exactly.

Afbeelding met tekst, schermopname, Lettertype, nummer

Automatisch gegenereerde beschrijving

 

4. It's advisable to maintain the name of the "flows.json" file unchanged.

Afbeelding met tekst, schermopname, software, Webpagina

Automatisch gegenereerde beschrijving

 

5. For enhanced security, we suggest encrypting your "credentials.json" file to prevent it from being stored as plain text within your GitHub repository. Choose a robust passphrase for encryption.

Afbeelding met tekst, schermopname, Lettertype, software

Automatisch gegenereerde beschrijving

   Setting up Git config

Similar to setting up Git on a new machine, you'll need to input your Git username and email address within Node-RED:

1. Navigate to Node-RED's "Settings" > "Git Config."

2. Enter your Git username and email address in the provided fields.

Afbeelding met tekst, schermopname, Lettertype, nummer

Automatisch gegenereerde beschrijving

 

3. Select your preferred commit type: Automatic or Manual. Opting for automatic commits means your flow changes will be automatically committed upon deployment, while manual commits require your explicit action to commit changes. Choose the option that best suits your workflow preference

Afbeelding met tekst, schermopname, software, nummer

Automatisch gegenereerde beschrijving

 

 

Create a git repository with access token

Let's create a Git repository and generate an access token. Afterwards, we'll set up a GitHub remote repository to link with Node-RED. To grant Node-RED the necessary permissions for pushing and pulling changes, we'll generate a developer access token. Here's how:

  1. Begin by creating a GitHub access token. Navigate to "GitHub > Settings > Developer settings > Personal access tokens > Tokens (classic)" (avoid using beta tokens as they may not function properly). Assign a name and expiration date to the token, and grant it all repository permissions—no additional permissions are necessary. Remember to copy your personal access token immediately as it won’t be visible again once generated.

 

Afbeelding met tekst, schermopname, Lettertype, nummer

Automatisch gegenereerde beschrijving

 

  1. Begin by creating a new repository. Note: Avoid selecting the "Add a README file" button as it would create an "origin/main" branch. Instead, you can create a README directly in Node-RED itself.

Afbeelding met tekst, schermopname, nummer, Lettertype

Automatisch gegenereerde beschrijving

3. Copy the HTTPS Github repository link. 

Afbeelding met tekst, Lettertype, nummer, lijn

Automatisch gegenereerde beschrijving

 

  1. Now, let's add the repository as an origin to Node-RED. Return to your Node-RED server and follow these steps:
  • Click on the hamburger menu.
  • Navigate to "Projects" > "Project settings" > "Settings".
  • Add a remote and paste the GitHub repository link into the provided field.

Afbeelding met tekst, schermopname, nummer, Parallel

Automatisch gegenereerde beschrijving

 

Now we are ready to commit our first changes to the remote github repository

1. Make the necessary changes in Node-RED and deploy them to prepare for committing.

2. Click on the "Project history" icon next to the debug button to access version control functionality. Then, "stage" your local changes by clicking the "+" button.

Afbeelding met schermopname, tekst, software, Computerpictogram

Automatisch gegenereerde beschrijving

 

3. Finally, commit the changes to a local branch (not remote) by clicking the "Commit" button.

Afbeelding met tekst, schermopname, software, Computerpictogram

Automatisch gegenereerde beschrijving

 

4. Finally, to push your changes to GitHub, navigate to the "Commit History" tab. Click the up and down arrow icon, then select a remote repository. Fill in your GitHub username and use your personal access token (created earlier) as the password.

Afbeelding met tekst, schermopname, software, Computerpictogram

Automatisch gegenereerde beschrijving

 

5. Afterward, create a remote branch, such as "main" or "dev".

Afbeelding met tekst, schermopname, Lettertype, nummer

Automatisch gegenereerde beschrijving

 

6. Once the new branch is created, you can push the settings to that branch.

Afbeelding met tekst, schermopname, Lettertype, nummer

Automatisch gegenereerde beschrijving

 

7. After completing these steps, you'll notice that the Node-RED changes have been successfully added to the GitHub repository.

Afbeelding met tekst, schermopname, nummer, Lettertype

Automatisch gegenereerde beschrijving

recommended