When using Express, I encounter difficulty in getting the css, js, and images to link up correctly when running the index.html file. The images are not showing up and the css and js files are not linking properly.
<link rel="stylesheet" type="text/css" href="css/main.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/main.js"></script>
img/logo.png
The directory structure is as follows:
root
app.js
package.json
node_modules
assets
img
css
js
templates
theme1
css
fonts
img
js
index.html
about.html
services.html
news.html
contact.html
In app.js:
var express = require('express');
var app = express();
var path = require('path');
app.get('/', function(req, res) {
//res.sendFile(path.join(__dirname + '/assets/templates/theme1/index.html'));
});
app.get('/about/', function(req, res) {
res.sendFile(path.join(__dirname + '/assets/templates/theme1/about.html'));
});
app.get('/services/', function(req, res) {
res.sendFile(path.join(__dirname + '/assets/templates/theme1/services.html'));
});
app.get('/news/', function(req, res) {
res.sendFile(path.join(__dirname + '/assets/templates/theme1/news.html'));
});
app.get('/contact/', function(req, res) {
res.sendFile(path.join(__dirname + '/assets/templates/theme1/contact.html'));
});
app.listen(3000);
I am seeking a better understanding of app.get
and app.use
, as well as how to use res.sendFile
effectively.
Thank you all for your help!