Reputation: 51
ExpressJS noob here. How do I call images stored in /public/images/ directory to my /public/stylesheets/styles.css
The following does not seem to work
.home-bg {
background-image:url('../images/bg.jpg');
}
Upvotes: 0
Views: 262
Reputation: 15627
I guess you are using express like this sample:
// config
app.configure(function() {
//..
app.use(express.static(__dirname + '/public'));
//..
}
express.static
, is responsible for serving the static assets and the argument refers to the root directory from which the static assets are to be served.
It does not refer to the path on your web page. refers to the directory in nodejs project. So we add __dirname, then the folder is relative to app.js
if, __dirname + '/public'
becomes in your http://www.example.com/
then /public/images
becomes http://www.example.com/images
.home-bg {
background-image:url('/images/bg.jpg');
}
Upvotes: 1
Reputation: 284
are you simply missing quotes on your url?, possible css error?
.home-bg {
background-image:url('../images/bg.jpg');
}
edit: heh, SO even formats it cute.
Upvotes: 0