0

I am new to the client side programming, building a nodeJS express sample application, but getting 404 error for loading script and CSS.

Please find the below wolder structure: Folder structure

HTML page is as below:

<head>
<meta charset="UTF-8">
<title>Favorite Book</title>
<link rel="stylesheet" href="../public/css/main.css" type="text/css"/>
<script type="text/javascript" src="../public/libs/js/angular.min.js"></script>
<script type="text/javascript" src="../public/libs/js/angular-route.min.js"></script>
<script type="text/javascript" src="../public/libs/js/jquery-1.12.2.min.js"></script>
<script src="../public/libs/js/script.js"></script>

Script error getting from browser is below:

GET http://localhost:3000/public/libs/js/script.js

1 Answer 1

3

you should set static path in app.js

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

then defind source without public path like this

<link rel="stylesheet" href="/css/main.css" type="text/css"/>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.