0

I have made a node.js server that users can upload images but I can't figure out how to display all of them. They are in a folder called "/uploads". And thanks for any help! If it matters here is my node.js code:

const express = require('express');
const upload = require('express-fileupload');
const path = require('path');
const app = express();
const serverport = 3000;

app.use(upload());

app.get('/', (req, res) => {
  res.sendFile(__dirname + '/index.html');
  console.log("Routes started!");
});

app.post('/', (req, res) => {
  if (req.files) {
    console.log(req.files);
    var file = req.files.file;
    var filename = file.name;
    console.log(filename);

    file.mv('./uploads/' + filename, function (err){
      if (err) {
        res.send(err);
      } else {
        res.sendFile(__dirname + '/uploads');
        res.send("File uploaded! Why not view others");
      });
    };
});

app.listen(serverport, () => {
  console.log('Server started on port ' + serverport + '!');
});
  • Welcome to Stack Overflow! Visit the [help], take the [tour] to see what and [ask]. Please first ***>>>[Search for related topics on SO](https://www.google.com/search?q=node+show+all+images+folder+site%3Astackoverflow.com)<<<*** and if you get stuck, post a [mcve] of your attempt, noting input and expected output – mplungjan Sep 29 '21 at 14:19
  • The same task https://stackoverflow.com/questions/2727167/how-do-you-get-a-list-of-the-names-of-all-files-present-in-a-directory-in-node-j – Vitaliy Rayets Sep 29 '21 at 14:21

0 Answers0