Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const path = require('path');
  3.  
  4. function showFile(folderName, done) {
  5.     fs.readdir(path.join('./public', folderName), (err, files) => {
  6.         files.some(file => {
  7.             done('http://localhost/public/' + folderName + '/' + file.toString());
  8.         });
  9.     });
  10. }
  11.  
  12. ///
  13.  
  14. app.get('/:id', (req, res) => {
  15.     showFile(req.params.id, file => {
  16.         res.render('index', {title: req.params.id, img: file});
  17.     });
  18. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement