Error: ENOENT: no such file or directory (Glitch project random-mcu)

I’m having issues trying to set up a Twitter bot on Glitch that will post a random image pulled from a remote server.

My project (random-mcu) is remixed from a standard Twitter bot, adding code from Random Image Twitterbot, which relies on pulling the images from Glitch’s assets folder. Since I have tens of thousands of images in my pool, I’m hosting them on my own website, but I’m running into this error:

Error: ENOENT: no such file or directory, scandir ‘http://www.erinlynch.me/randommcu/images/

I’ve made sure the directory’s permissions aren’t restricting access, but haven’t been able to get around the error. Is there something I’m missing?

Thanks for any help!

1 Like

It looks like you’re trying to fetch images from your remote server using fs.readdir. Something to note about Node.js File System library:

The fs module provides an API for interacting with the file system

So that won’t work for fetching remote resources, like images on your web server. (it will work for files in your glitch directory, e.g. if you’d copied the images to your assets folder.)

Instead, you can use http.get

1 Like

Thank you for your help! I followed your advice and that particular error went away, but different code broke. I fought with it for a while and decided to break down the pool of images and upload them to Glitch’s assets so I could simply remix Random Image Twitterbot , and now the bot’s up and running. I’ll just refill the assets folder periodically so the bot has enough images.

Again, thanks so much!

1 Like