I am currently working on a Video Portal Project that involves organizing videos into different folders on the server. Utilizing nodejs technology, my goal is to create a function that can access and display all video content within a specific folder. At the moment, the code I have only serves a single file rather than an entire folder. I would greatly appreciate any contributions or suggestions to help me achieve this functionality. Thank you.
let express = require('express');
let bodyParser = require('body-parser');
let path = require('path');
let fs = require('fs');
var ejs=require('ejs');
let port = process.env.PORT || 4000;
let videosPath = './videos/';
let app = express();
// Set view engine
app.set('view engine', 'ejs');
app.set('views', path.join( __dirname, 'views'));
// Using body parser middleware
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({extended: false}));
// Route to handle fetching videos from a specific folder
app.get('/videos/:id',function(req,res){
fs.readdir(`./videos/${req.params.id}`, (err, files) => {
console.log(files);
res.render('pages/index',{videos:files,cateogry_id:req.params.id});
});
});
// Default route
app.get('/',function(req,res){
res.render('index');
});
app.listen(port, function(){
console.log("Server running on port 4000");
});