0

I'm working on mern project and need to find a way to store images in the project directory. The images are originally stored in the database. Once I obtain the images I need to save them in project folder like assets. Is there a way to do this with just JavaScript?

2
  • I don't know what "mern project" is, but you typically can't write to the local filesystem with JavaScript Commented May 27, 2019 at 10:53
  • MERN as in mongoDB, Express, React and nodejs Commented May 27, 2019 at 11:01

1 Answer 1

0

If you are writing server-side javascript code that queries a database, then yes. React code is typically for creating client side/front end code that runs within a browser however and won't be able to interact with a server's database except through APIs.

From your edit saying you're using Express and MongoDB, it sounds like you should be able to use the following links to guide you in accomplishing what you're trying to do:

Store images in Mongodb serve them with Nodejs

Sign up to request clarification or add additional context in comments.

2 Comments

I guess my question isn't very clear. My images are originally stored in mongodb. I have an API that will fetch the images when I need them. But once I have them I need to store it in my project folder. I have some images stored in my project directory in assets folder. I want to store the images I get from mongodb in that assets folder.
So it sounds like you need to pull the binary data from MongoDB and use the basic file system IO calls to write the file to the assets folder stackoverflow.com/questions/43487543/… That same link above should help guide you in the initial pull of the binary data from Mongo

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.