Express.js - How to access the value of a variable within a route

0

I have the following function

 function fileList() {
  const uploadFolder = './public/uploads/';
  fs.readdir(uploadFolder, (err, files) => {
    files.forEach(file => {
      let arquivoNome = file;
      console.log(arquivoNome);
    });
  });
 }

I'd like to use the value of the variable "fileName" in the following route:

router.get('/dashboard', (req, res) => {
  Image.findOne({ imagemNome: arquivoNome }).then(imagem => {
    res.render('dashboard', {
      usuario: req.user,
      imagem: 'uploads/${imagem}'
    });
    console.log(imagem);
  });
});
    
asked by anonymous 07.07.2018 / 23:42

0 answers