Window object not available


I have developed a custom node, which is using some front end objects,

1 Mar 12:09:40 - [warn] [imodel-query/imodel-query] ReferenceError: window is not defined


The runtime portion of your node runs in the node.js runtime, not in the browser. This means none of the browser-specific globals, such as window, exist.



So, what if I want to use some front end library (which is using window object) in my custom node.
like, I drag an rest api node, and attach my custom node to it. and then have it working.



What sort of library do you mean? Have you got an example?

You cannot use browser-specific libraries in the runtime part of your code; you need to use a node.js module.



Libraries that usually interact with the front end, but are running on node.js .
and what do you mean by node.js module? what module can help me here?



@talhairfanbentley by node.js module I mean a module published to npm for use with node.js.

You haven't explained what you are trying to do, so I can't point at any specific module to help you.

A node runs in the node.js runtime - it does not have anything to do with the browser. The only browser part is the node's edit dialog. Do you mean you want to use a 3rd party library when you are editing your node in the Node-RED editor?

Please describe in detail what you are trying to do.



okay It's like this:
I'm creating a custom node. but I also have few external libraries with are related to imodel . To be exact I'm using imodel js front end libraries. in which the window object is being used.
Now I'm not sure what i'm asking is possible or not.



A node-red node runs as a headless piece of code in the server. It doesn't display anything on the screen. The imodel.js library you've linked to appears to be a library for displaying models on a webpage. Node-RED nodes don't run in the webpage - they run on the server.

There are modules such as node-red-dashboard that can be used to generate web-page dashboards served from node-red. It might be you want to create a custom node for node-red-dashboard that can be used to add an imodel.js viewer to a node-red-dashboard web page. But I am just guessing....

What do you want your custom node to actually do? Describe what functionality you want it to provide.



Certainly you guess gives me some idea.
and as for now, I just need to query an imodel and display the result in the page or console. But only using frontend libs.



For this I suspect the node-red-contrib-uibuilder project may be more appropriate as it lets you build a Node-RED dashboard the way to want using whatever libraries you want.



Yes, uibuilder can help here.

You will install the ibuilder nodes to your userDir folder - normally ~/.node-red and add the names to Node-RED's settings.js file as per the documentation for uibuilder.

Then you can add a uibuilder node to your flow and it will make the front-end libraries available.

You will need to then amend the default index.html file to load the libraries into the browser & make any required changes to the rest of the web page. Then you may have to alter index.js to do whatever imodel needs.

uibuilder then also provides you with a communications channel between the Node-RED server back-end and your front-end code so that you can pass data back and forth as needed.