To answer your original question and Steve's query.
Yes, it is certainly possible. And you might want to do so because the node does not cover all of the Cheerio functionality (or at least that's what I remember from when I last did it maybe a year ago).
I need to make my messages clearer.
There are 2 distinct strategies that I've tried:
Cheerio imported as a module in a Node Function: I don't know how to import and use Cheerio in a node function, as it gives the error from my first message in the thread.
Alternative: node-red-contrib-cheerio-function: When trying to use this, I also receive errors, as shown in the other messages above.
@Steve-Mcl, the $ you mentioned was a problem I had when using 'node-red-contrib-cheerio-function' and not importing Cheerio in a basic node function. That's why I expected $ to be available as in the example in the documentation, since I didn't import Cheerio in this case. doc:This function block extends the functionality of the normal node-red function block with the ease of parsing the msg.payload it it is of type string directly into te $ selector.
@TotallyInformation, thanks. From what I understood, you are talking about strategy 1, which was my initial intention. Correct?
So, how would I need to configure and use it in order to avoid the errors that I mentioned in the initial message of the thread?
This flow works. It is the basic example given on the cheerio GitHub README but wrapped up as a Node-RED flow using a function. Sorry, I seem to have deleted my original example, I think it was something I quickly did for work.
Thank you for clarifying. Apparently, your example was the approach I tried in the first message of the thread.
I tried exactly what you mentioned again, and I'm still getting the same error that I shared in the first message of the topic: function : (error) "Error: Cannot find module '/data/node_modules/cheerio/index.js'. Please verify that the package.json has a valid "main" entry"
Please note that the error occurs during the deployment of the flow, even before trying to run it. And I'm using node-red installed by CapRover on a Hetzner VPS.
OK, so at least we now know that it is something local to your device which is progress of a sorts.
Can you get to a command prompt on the device? If it is in Docker, there is a command (that I can never remember off the top of my head) that gets to a command line inside your docker container and that's where you need to end up.
Then if you can get to the /data/ folder, you can check whether cheerio actually got installed and if not, you can do a manual install npm install cheerio - but that must be in the /data/ folder.
docker exec -it container-name sh
Will start a terminal session inside the container.
I'm really out of ideas I'm afraid. Everything seems OK to me.
The only thing left that I can see is
Not sure what that is but could it be that it is having an impact? Can't see that it should be, but ...
If you can't get it working directly, there are only a couple of workarounds I can think of. One would be quickly knocking up your own custom node to see if that worked. The other would be to do the request from the browser which you could do via uibuilder.