I am working on a MEAN application. I constructed my directory structure just using the express "app name" command, and I've created a index.ejs file which all my front end javascript file but for some reason when I run the app, it returns 404 not found for the js files. What is the proper path that I need to use to properly include my app.js, loginController.js, mainController.js, and registerController.js to my index.ejs.
This is the index.ejs, and I included the js files on the bottom. Is my src path wrong? Ango
<body ng-app="secret">
<div id="mainBar">
<div id="mainBarWrapper">
<div id="siteLogo">
<img src="images/mimiLogo.png" alt="mimi"/>
</div>
<div>
<ul id="navBar">
<li><a ui-sref="main">Home</a></li>
<li> | </li>
<li><a ui-sref="login">Login</a></li>
<li> | </li>
<li><a ui-sref="signUp">Sign Up</a></li>
</ul>
</div>
</div>
</div>
<div ui-view></div>
</body>
<script src="../public/javascripts/app.js"></script>
<script src="../public/javascripts/mainController.js"></script>
<script src="../public/javascripts/loginController.js"></script>
<script src="../public/javascripts/registerController.js"></script>
Make your public folder static in your node server
app.use(express.static('public'));
or
put a route for your file.
As you can see your image is being loaded. But your scripts are not. You need to remove the ../public/
part of your url to be just javascript/index.js
This is from expresses static folder public.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.