Skip to main content
deleted 64 characters in body; edited tags; edited title
Source Link
200_success
  • 144.2k
  • 22
  • 188
  • 473

Reading Files Asynchronouslyimage files asynchronously and Displayingdisplaying them on the page

Hello I am trying to display images from a folder in my project using the "fs" module with NodeJS,. I need to read all images in a directory and run them in a loop for them to be displayed. I was able to do it but I'm not sure if this is the proper or good way to do it. Thanks in advance for your help.

I inserted my readdir (Reading Files Asynchronously) inside my Homepage route. The images were displayed but I have no one to ask if I did it the proper way. Please help, thank you!

const express = require('express');
const router = express.Router();
const fs = require('fs');

router.get('/', function(){ 
    fs.readdir('./assets/images/', (err, files) => {
        if(err) {
            throw err;
        }
        res.render('home', {
            files: files
        });
    });
});

module.exports = router;

Reading Files Asynchronously and Displaying them on the page

Hello I am trying to display images from a folder in my project using the "fs" module with NodeJS, I need to read all images in a directory and run them in a loop for them to be displayed I was able to do it but I'm not sure if this is the proper or good way to do it. Thanks in advance for your help.

I inserted my readdir (Reading Files Asynchronously) inside my Homepage route. The images were displayed but I have no one to ask if I did it the proper way. Please help, thank you!

const express = require('express');
const router = express.Router();
const fs = require('fs');

router.get('/', function(){ 
    fs.readdir('./assets/images/', (err, files) => {
        if(err) {
            throw err;
        }
        res.render('home', {
            files: files
        });
    });
});

module.exports = router;

Reading image files asynchronously and displaying them on the page

I am trying to display images from a folder in my project using the "fs" module with NodeJS. I need to read all images in a directory and run them in a loop for them to be displayed. I was able to do it but I'm not sure if this is the proper or good way to do it.

I inserted my readdir (Reading Files Asynchronously) inside my Homepage route. The images were displayed but I have no one to ask if I did it the proper way.

const express = require('express');
const router = express.Router();
const fs = require('fs');

router.get('/', function(){ 
    fs.readdir('./assets/images/', (err, files) => {
        if(err) {
            throw err;
        }
        res.render('home', {
            files: files
        });
    });
});

module.exports = router;
deleted 3 characters in body
Source Link

Hello I am trying to display images from a folder in my project using the "fs" module with NodeJS, I need to read all images in a directory and run them in a loop for them to be displayed I was able to do it but I'm not sure if this is the proper or good way to do it. Thanks in advance for your help.

I inserted my readdir (Reading Files Asynchronously) inside my Homepage route. The images were displayed but I have no one to ask if I did it the proper way. Please help, thank you!

const express = require('express');
const router = express.Router();
const fs = require('fs');

router.get('/', function(){ 
    fs.readdir('./assets/images/', (err, files) => {
        if(err) {
            throw err;
        }
        res.render('home', {
            files: files
        });
    });
});

module.exports = router;
```

Hello I am trying to display images from a folder in my project using the "fs" module with NodeJS, I need to read all images in a directory and run them in a loop for them to be displayed I was able to do it but I'm not sure if this is the proper or good way to do it. Thanks in advance for your help.

I inserted my readdir (Reading Files Asynchronously) inside my Homepage route. The images were displayed but I have no one to ask if I did it the proper way. Please help, thank you!

const express = require('express');
const router = express.Router();
const fs = require('fs');

router.get('/', function(){ 
    fs.readdir('./assets/images/', (err, files) => {
        if(err) {
            throw err;
        }
        res.render('home', {
            files: files
        });
    });
});

module.exports = router;
```

Hello I am trying to display images from a folder in my project using the "fs" module with NodeJS, I need to read all images in a directory and run them in a loop for them to be displayed I was able to do it but I'm not sure if this is the proper or good way to do it. Thanks in advance for your help.

I inserted my readdir (Reading Files Asynchronously) inside my Homepage route. The images were displayed but I have no one to ask if I did it the proper way. Please help, thank you!

const express = require('express');
const router = express.Router();
const fs = require('fs');

router.get('/', function(){ 
    fs.readdir('./assets/images/', (err, files) => {
        if(err) {
            throw err;
        }
        res.render('home', {
            files: files
        });
    });
});

module.exports = router;
Source Link

Reading Files Asynchronously and Displaying them on the page

Hello I am trying to display images from a folder in my project using the "fs" module with NodeJS, I need to read all images in a directory and run them in a loop for them to be displayed I was able to do it but I'm not sure if this is the proper or good way to do it. Thanks in advance for your help.

I inserted my readdir (Reading Files Asynchronously) inside my Homepage route. The images were displayed but I have no one to ask if I did it the proper way. Please help, thank you!

const express = require('express');
const router = express.Router();
const fs = require('fs');

router.get('/', function(){ 
    fs.readdir('./assets/images/', (err, files) => {
        if(err) {
            throw err;
        }
        res.render('home', {
            files: files
        });
    });
});

module.exports = router;
```