Reputation: 15094
Below image depicts my node js application directory structure in windows OS.
In express.js file I have mentioned
app.use( 'static', express.static('../bower_components/'));
I would like to refer to static files bootstrap.min.js and bootstrap.min.css which are in /bower_components/bootstrap folder in my view file which is in /views/users/index.js.
I have mentioned below 2 lines in my view file , but it's not working.
<link href="../static/bootstrap/dist/css/bootstrap.min.css">
<script src="../static/bootstrap/dist/js/bootstrap.min.js"></script>
Please let me know what needs to be modified.
Upvotes: 0
Views: 89
Reputation: 2157
Your path in the view should be
<link href="/bootstrap/dist/css/bootstrap.min.css">
<script src="/bootstrap/dist/js/bootstrap.min.js"></script>
Upvotes: 1
Reputation: 445
Well, I have something which is similar to yours.. Maybe this could help you:
var flash = require('connect-flash');
var path = require('path'),
fs = require('fs');
var http = require('http')
...
app.use(express.static(path.join(__dirname, 'public')));
app.set('views', __dirname + '/views');
My view look like this:
<!DOCTYPE html>
<html lang="en">
<head>
<% include ../partials/head %>
</head>
<body class="container">
<header>
<% include ../partials/header %>
</header>
<main>
<div class="jumbotron">
<h3>Welcome in Dubai!,</h3>
</div>
</main>
<footer>
<% include ../partials/footer %>
</footer>
</body>
</html>
To give you more information about my folder structure. I have a folder called views with two subfolders pages and partials
Best regards, Nazar
Upvotes: 0