yet another static files newbie question

101 views
Skip to first unread message

pierre

unread,
Dec 30, 2016, 12:34:15 AM12/30/16
to Express
Hi there,
Im currently trying to understand express and have the following app which does not seem to serve my static files. I looked a lot at online tutorials but nothing seems to work so far. Could you please tell me where I'm wrong?

here is my app.js:

var express = require('express');
var path = require('path');


var app = express();


app
.use(express.static(path.join(__dirname, 'public')));
app
.use(express.static(path.join(__dirname, 'static')));




app
.listen(13245);

my directory looks like that:

..
-public
--index.html
-static
--css
---styles.css
--javascript
---nav.js
app
.js

and my index.html has the following header:

<head>
 
<title>...</title>
 
<meta charset="utf-8">
 
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
 
<link rel="stylesheet" href="css/styles.css" />
 
<link rel="shortcut icon" href="favicon.ico"/>
 
<script src="javascript/nav.js"></script>
</head>

as a result, the index.html fil is served. But I have a GET error for the css and js files.
What should I change?
Cheers

Ray D

unread,
Jan 3, 2017, 4:29:37 AM1/3/17
to Express
You could debug by this way
1>console.log( path.join(__dirname, 'static'))
2>Open the browser dev tool to check what the css'url the browser try to get.
Reply all
Reply to author
Forward
0 new messages