Surendra Kumar Ahir Surendra Kumar Ahir - 4 years ago 222
Node.js Question

Display images from Gridfs

I am totally new to node and want to know how to download an image with grids. Please help me.
I use mongoose and node for storing images, side front nodeJs. I want to download an image using the grid in nodejs. (){
gfs.exist({ _id: id }, function(err, found) {
gfs.createReadStream({ _id: id }).pipe(res);

Any help would be greatly appreciated.

Answer Source

According to your question, gridfs is the best thing you can use.

 if (fileExists(image_name) == false) { //it check that file exist or not   
            var file = fs.createWriteStream(image_name);
            http.get(url, function (response) {
        else {
            console.log('already exist.');

I am using this in my code , hope this works for you.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download