How to run WGET programatically?

So I have this CANVAS project where I need to refer to the image canvas will edit with a filepath (URLs not supported) and there is the WGET console command that allows me to download the file locally from an URL, but how would i do this dynamically? As in I want to receive text input from the user (An image URL) and my code will automatically WGET to download the image so canvas can use it. Is this possible? If so, how? (basically how do i run any glitch console command with code?)

Hey @CheatTriggers you can run wget using Node’s child_process.exec(). You can also use an NPM module;, for example, uses snekfetch, but I believe that’s been deprecated in favor of node-fetch - I just haven’t gotten around to updating that project yet.

Hope this helps!

1 Like

What if i want to run it on the main process instead of a child one though?

child_process is how you get Node to fork a thread to do operating system tasks. Not sure why this would be problematic; did you read the docs there? If you want to download a file within the Node process then use node-fetch or something like it.

You can run any bash command via the package.json scripts, but that won’t allow you to do so in reaction to anything in the Node process (like from a bot command or an Express route, for instance).

1 Like

Personally, I use node-cmd (Visit)


Oh that’s a pretty nice option. Thanks for the pointer!