Reputation: 1699
I have the following folder structure in my node project (using node, webpack, and express):
dist/
(folder containing .js files)views/
(folder containing static .html files referencing .js files in above mentioned dist folder)The index.html (located in the above mentioned views
folder) file contains the following:
<script type="text/javascript" src="../dist/test.js" ></script>
In the app.js for the node application I am serving the static .html page in the following manner:
router.get('/setup', function(req, res){
res.sendFile(path.join(__dirname, './views/index.html'));
});
The problem is that the .html renders properly but it is unable to find the .js file which it references. How do I fix this?
Upvotes: 0
Views: 79
Reputation: 492
You can do the following -
app.use(express.static('dist'));
router.get('/setup', function(req,res) {
res.sendFile(__dirname + '/views/hello.html');
})
And in your html file just do this -
<script type="text/javascript" src="test.js" ></script>
Upvotes: 0
Reputation: 1068
Use this src="./dist/test.js" instead of src="../dist/test.js"
. May be this will be the problem
Upvotes: 0
Reputation: 5901
Inside your app.js file add line:
app.use('/source/', express.static(__dirname + '/path_to_js_folder'));
And modify your < script > tag as:
<script type="text/javascript" src="/source/test.js" ></script>
Upvotes: 0