Is it possible to import from node.js to Processing?

Hello,
I’m curently trying to make a twitter bot using node.js and Processing.
The node.js select some data from twitter and I’d like to use these data to make an image using Processing. Then export this image back to node.js to finally tweet it.

Following The Coding Train’s tutorial I know how to export an image to node.js.
But is it possible to use some variables I got from node.js, as variables on Processing ?

I hope my question is clear enough. I can clarify if needed.

Thanks in advance !

UPDATE : I found out that you can import text files using loadStrings(). So I’m just importing ‘params.txt’ files on the ‘date’ folder of the project and then read the data on the file.
I don’t know if it’s the best way to do it but it works !

2 Likes

If this approach works for you, then we can call this case closed. If you want to optimize it, I have some untested ideas.

I believe you are calling Processing java as shown at this moment in the video here. As I see in this video, Dan is using processing-java command to get the sketch to run. You will need to modify it so you can pass parameters to your “executable” sketch. To do this, you might not be able to use “processing-java” as I don’t think using this command allows you to pass parameters. Instead, you will create the executable of your application and then you use exec() (as shown by Dan) to call your executable sketch. You can check the documentation of child_process’s exec() where it shows how to pass parameters to your executable. I am assuming you are not passing lots of data to your sketch but more like the equivalent of a tweet. An explicit example: exec('"/path/to/test file/test.sh" arg1 arg2');

Another idea is to use p5.js instead of using Processing java so you work only in js. If you are working with images and capturing/saving image buffers, then it might require some additional setup like using puppetteer. You could share more details about the specifics and requirements of your app and you might get more suggestions here in the forum.

Kf

1 Like

For more on using node.js with p5.js, see https://github.com/processing/p5.js/wiki/p5.js,-node.js,-socket.io

Or Google “p5.js node.js” for Coding Train videos