I am trying to deploy my node js express app. But it's getting wrong path.
app.use("/", express.static(__dirname + "/public")) In server.js And my paths for styles are
Directory for style is /public/styles/brandAnimation.cssI am trying to deploy my node js express app. But it's getting wrong path.
app.use("/", express.static(__dirname + "/public")) In server.js And my paths for styles are
Directory for style is /public/styles/brandAnimation.cssIf your link in your HTML page is:
<link rel="stylesheet" href="/styles/brandAnimation.css">
And, /public
is a sub-folder from where your server file that contains app.use("/", express.static(__dirname + "/public"))
is located and brandAnimation.css
is in that /public
folder under styles/brandAnimation.css
, then this should work.
I'd also recommend that you change your express.static()
line to just this:
app.use(express.static(__dirname + "/public"));
Basically, you need to URL for your stylesheet page to start with a /
and it needs to be additive to whatever directory you told express.static()
to look into.
If this doesn't work for you, then we need these pieces of information:
app.use(express.static(...))
statement.To troubleshoot, add this as the very first middleware in your Express server:
app.use((req, res, next) => {
console.log(`Incoming request: ${req.path}`);
next();
});
This will show what exact requests are arriving at your Express server. If nothing shows here for the css file, then perhaps your nginx is not configured properly.