Reputation: 1900
I'm starting to learn Nodejs with a simple app. Google Chrome can't seem to find my app.js file in my /assets/js.app
And then as you can see, I believe I have the paths set ups correctly
Instead of {{ vm.message }} it should say Hello World.
Chrome keeps telling me it can't find the app.js file in the index.ejs template file, which looks like this
<html ng-app="TestApp">
<title>The MEAN Stack</title>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.js"></script>
</head>
<body ng-controller="MainController as vm">
{{ vm.message }}
<script src="/assets/js/app.js"></script>
</body>
</html>
Upvotes: 0
Views: 778
Reputation: 191779
When using express.static
, the optional route prefix is not actually part of the file path, but rather it is appended to the url. You can use /assets/assets/js/app.js
, but it may be better to just remove the prefix: app.use(express.static(__dirname + "/public"))
.
I would also say that assets
should be reserved for things like images and that js
and perhaps even css
belong in their own higher level directories, but this is debatable.
Serving static content from express
is fine for development or toy apps, but in a real production app you should look into a better static file server than node.js.
Upvotes: 2