node.js - can't load my files with express3


I am using express3 and when I'm trying to load my html/javascript/css files it loads the html without the css.

I'm using this code to load the files -

express.get('/', function (req, res) {

So what can I do?

Problem courtesy of: Israelg99


First, link the css and javascript to the page via tags in the header of your HTML

<link rel='stylesheet' href='/path/to/style.css' />
<script src='/path/to/javascript.js'></script>

Be sure that you're using the static middleware in your app.use() section, this will tell Express where to find your static files.

app.use(express.static(__dirname + '/public'));

Now, your Express app should serve your static css and js files.

Solution courtesy of: Hacknightly


You link to css and javascript from the html page...

Try looking at the static files example app in the express github repo:

Basically you make another http request for static files (.js, .css)

Discussion courtesy of: Benoir

This recipe can be found in it's original form on Stack Over Flow.