Search code examples
javascriptexpressparse-platformejs

Add stylesheet to express app


For my web app I am using ejs with express and parse.com on the backend. I am having an issue with adding stylesheet and all the answers to this question I was able to find are not solving my problem. I thought maybe showing my code would help to solve it. My stylesheet directory is public/css/style.css

See below the code from cloud/app.js

var express = require('express');
var app = express();

app.use(express.static(__dirname + '/public'));
app.set('views', 'cloud/views');  // Specify the folder to find templates
app.set('view engine', 'ejs');    // Set the template engine
app.use(express.bodyParser());    // Middleware for reading request body

var Movies = Parse.Object.extend('Movies');

app.get('/', function(req, res) {

    var query = new Parse.Query(Movies);
    query.find({

        success: function(results) {
            res.render('movie-list', { movies: results });
        },

        error: function(results, error) {

        }

    });
});


app.listen();

And here is my template, located in the views:

<html>
    <head>
        <title>Movies</title>
        <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.2/css/bootstrap.min.css"    rel="stylesheet">
        <link href="css/style.css" type="text/css">
    </head>
    <body>
        <h1>Movies</h1>
        <ul id="categoryList" class="list-group">

            <%
                for (var i = 0; i < movies.length; i++)
                { 
                var movie = movies[i];
            %>

            <li class="list-group-item"><%= movie.get('Movie')%></li>

            <%
                }
            %>

        </ul>

    </body>
</html>

Any help would be greatly appreciated! Thank you!


Solution

  • I haven't tested your code, but looking at my Parse web apps, my links to stylesheets start with /

    Try changing

    <link href="css/style.css" type="text/css">
    

    to

    <link href="/css/style.css" type="text/css">
    

    Good luck!