Reputation: 4461
CODE:
app.js
//Static Folder
app.use(express.static(path.join(__dirname, "/public")));
section1/index.ejs
<script src="/public/js/firebase.js"></script>
<script src="/public/js/angular.js"></script>
<script src="/public/js/angularfire.js"></script>
<script src="/public/js/jquery-3.1.1.min.js"></script>
PROBLEM:
Error 404 for all those files when I load section1/index.ejs
What is missing ? What mistake have I made ?
Upvotes: 1
Views: 149
Reputation:
Try using:
app.use('/public',express.static(path.join(__dirname,'/public')));
And I think if you want to use it as a middleware without a virtual path, you should use it like this:
app.use(express.static('public'));
Without defining the whole path, Express will get the folder for you automatically.
Upvotes: 0
Reputation: 18546
You need to pass a first argument to app.use
, which will be the public path.
app.use('/', express.static(__dirname + '/public'));
Then on the client:
<script src="/js/firebase.js"></script>
You can also use /public
instead of /
.
Upvotes: 4