I have multiple HTML pages with CSS and js files that work(if I open an HTML page on its own using chrome for example) I have tried to use these pages inside a node js project I created. but for some reason, it doesn't recognize the js file and doesn't apply the CSS design. I had installed path, but I still can't get node js to recognize the js file. I'm referring to the js file inside the HTML code by
You need to let the node know that you want to use these files in your project. Or you have to get permission to use these files from the node.
To do this, create a directory called 'public' in the root path of your project
And use the following code in the main file of your project
const path = require('path');
const express = require('express');
app.use(express.static(path.join(__dirname, 'public')))
The above code means that any file in the public folder (such as js css img) is allowed to access and use