0

This is my project structure:

public -js --angular.min.js --angularApp.js templates -views --index.ejs

This is my index.ejs file:

<html>
    <head>
        <title>My Angular app!</title>
        <script type='text/javascript' src="../../public/js/angular.min.js"></script>

    </head>

    <body ng-app="flapperNews" ng-controller="MainCtrl">
        <div>
            {{test}}
        </div>
        <script type='text/javascript' src="../../public/js/angularApp.js"></script>
    </body>

</html>

When I run this I get a 404 not found error on the js files.

I tried adding this to middleware.js in the routes folder:

app.use("/public/js/angularApp.js", express.static(__dirname + '/public/js/angularApp.js'));

But this didnt work, I also tried using this path:

/public/js/

But also didn't work.

How can I correctly reference a Javascript file in a ejs file?

1 Answers1

0

The public folder is you root directory from the vistor perspective. So in your case it should be

<script type='text/javascript' src="/js/angular.min.js">