How do we store user-uploaded photos in a social media app in express.js?

I always thought we should use the public folder to serve any kind of files but this isn't true? (just realised that the public means publicly available xD) For instance, say we have a social media blog where we can create a post and upload photos. The photos need to be stored somewhere on the server, right? Where do we store that? I used to store that in the public folder in some of my projects but this isn't good? If we are using express I'm confused, we would need to use express.static() for 2 different folders?
2 Replies
Faker
FakerOP2mo ago
Users can always see my project structure/folders, no?
Anurag M
Anurag M2mo ago
only folders you expose with express.static() like the public folder are accessible to users. If you want to serve other folders ike /uploads or a custom folder you can use express.static() with middleware for access control or setup a custom express route

Did you find this page helpful?