'How to serve static files from local directories using nodejs express?

I'm working on a Nodejs project that I will run only on my local computer (OS: Windows 10) and serve images and videos from local directories in computer drives (for example: { c:..\ Or D:.... or E:.... }).

Note: This is my first project using node js.

I've searched for answers but none of them helped me.

What is the problem that I have?

The problem I have is that the app can't read images from local directories and I get this error from the console on google chrome:

Not allowed to load local resources: file:///D:/Media/movies/action/Point Blank/folder.jpg

How can I enable reading from local directories in express node js without the need to run chrome with disabling security commands?

I don't know what is the problem, is it because of the slash or backslash in the URL path? or is there something I need to add in app.js?

Some Code lines from the project:

// Image 

<img src="D:/Media/movies/action/Point Blank/folder.jpg" alt="">

//App.js:

const express = require('express');
const path = require('path');

const app = express();

// Servie Static files
app.use('/assets', express.static('assets'))


app.set('views', [
  path.join(__dirname, '../views'),
  path.join(__dirname, '../views/admin'),
  path.join(__dirname, '../views/admin/categories'),
  path.join(__dirname, '../views/admin/users'),
  path.join(__dirname, '../views/guest'),
  path.join(__dirname, '../views/guest/home'),
  path.join(__dirname, '../views/guest/categories')
]);
app.set('view engine', 'ejs');



app.listen(PORT, () => {
  console.log("app is running in mode:", process.env.NODE_ENV);
});




Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source