Serve static files
Node-RED allows you to serve static resources (local files) such as JavaScript, CSS, and image files. These resources do not require flow configurations, making them especially useful for serving assets that are shared across multiple web pages.
By default, serving static files is disabled. You can enable this functionality by modifying the settings.js file in the case of a standard Node-RED installation, or by modifying the olca.settings.json file if you are using OL Connect Automate (recommended).
Tip: This functionality is similar to serving static HTTP resources in OL Connect Workflow.
More information on serving local resources is available under configuration in the Node-RED user guide.
Note: For a more flexible and portable solution, especially when working within project directories, consider using a flow-based setup to serve local files dynamically. See Serve local files using a flow.
Serving Static Files in Node-RED
To serve static files, specify the local directory from which to serve the content and the corresponding root folder for the URL path.
Example setup:
-
Files are served from the
C:/workspace/staticdirectory. -
Root set to
/assets. -
The static files are accessible via
http://localhost:1880/assets.
A files such as styles.css, located in the C:/workspace/static folder, will be accessible at:
http://localhost:1880/assets/styles.css
Modifying olca.settings.json
This the recommended method for enabling serving static files. The olca.settings.json file is created when OL Connect Automate is installed with the Windows installer.
This file is located in the User Data directory defined during the installation. By default, this is:
C:\ProgramData\Objectif Lune\OL Connect Automate
Modifying this file ensures that your settings remain intact when updating OL Connect Automate.
Add the following section to the olca.settings.json file. Remember to escape the backslashes in Windows paths:
"httpStatic": [
{
"path": "C:\\workspace\\static\\",
"root": "/static/"
}
]
Caution: Ensure that the olca.settings.json file contains valid JSON. Invalid JSON will prevent OL Connect Automate from starting.
Modifying settings.js (not recommended)
You can configure static file serving in the settings.js file used by Node-RED. This method is not recommended because changes made here may be overwritten during updates to OL Connect Automate Automate or Node-RED. This file is located in the User Data directory defined during the installation.
Here’s how you would configure static files in settings.js:
httpStatic: [
{
path: "C:\\workspace\\static\\",
root: "/static/"
}
]