Node-RED 1.3以降
A node may need to load extra resources in the editor. For example, to include images in its help or to use external JavaScript and CSS files.
In earlier versions of Node-RED, the node would have to create custom HTTP Admin end-points to serve up those resources.
With Node-RED 1.3 or later, if a module has a directory called resources
at the
top level, the runtime will make anything in that directory available to the editor
under the url /resources/<name-of-module>/<path-to-resource>
.
For example, given the following module structure:
node-red-node-example
|- resources
| |- image.png
| \- library.js
|- example-node.js
|- example-node.html
\- package.json
A default Node-RED configuration will expose those resource files as:
http://localhost:1880/resources/node-red-node-example/image.png
http://localhost:1880/resources/node-red-node-example/library.js
Note: If using scoped module names then the scope needs to be included in the path:
http://localhost:1880/resources/@scope/node-red-contrib-your-package/somefile
When loading resources in the editor, the node must use relative URLs rather than absolute URLs. This allows the browser to resolve the URL relative to the editor URL and removes the need for the node to know anything about how its root paths are configured.
Using the above example, the following HTML can be used to load those resources in the editor:
<img src="resources/node-red-node-example/image.png" />
<script src="resources/node-red-node-example/library.js">
Note the URLs do not start with a /
.
Node-RED: Low-code programming for event-driven applications.
Copyright OpenJS Foundation and Node-RED contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.
The OpenJS Foundation | Terms of Use | Privacy Policy | OpenJS Foundation Bylaws | Trademark Policy | Trademark List | Cookie Policy