0

I'm trying to add some styling to a very simple app I did with Node.js. I tried all the answers possible but the CSS file continue without showing up. I'd be glad if someone could help me to spot the error :) Thanks in advance.

I'm working in goormIDE.

My folders:

>app.js
>public
    >css
      >styles.css
>views
  >search.ejs

My code in app.js

var express = require("express");
var app = express();
var request = require("request");

app.use(express.static(__dirname + '/public'));

app.set("view engine", "ejs");

app.get("/", function(req, res){
  res.render("search");
  });

app.get("/results", function(req, res){
    var query = req.query.search;
    var url = "http://omdbapi.com/?s=" + query + "&apikey=thewdb";
    request(url, function(error, response, body){
    if(!error && response.statusCode == 200) {
        var data = JSON.parse(body);
        res.render("searchresults", {data: data});
        }
    });
});

app.listen(9000, function(){
    console.log("Movie App has started!!!");
});

search.ejs:

<!DOCTYPE html>
<html>
    <head>
        <title>Central Cinema</title>
         <link rel="stylesheet" 
      href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
        <link rel="stylesheet" type="css" href="/css/styles.css"/>
    </head>

<body>
    <div class="container">
        <div class="landing-header">
            <h1>Search For a Movie</h1>

            <form action="/results" method="GET">
                <input type="text" placeholder="search term" name="search">
                <input type="submit">
            </form> 
        </div>
    </div>  
</body>

styles.css

body {
    color:red;
}
5
  • I think just remove / before css in the line <link rel="stylesheet" type="css" href="/css/styles.css"/> Commented Sep 28, 2019 at 8:28
  • I tried that already :) and it didn’t solve the problem. Commented Sep 28, 2019 at 8:33
  • can you please show the output, Do try one thing, Being on web page Press ctrl+u then click on this line /css/styles.css you will know that whether css being liked or not and if yes then what's the URL for the css Commented Sep 28, 2019 at 8:49
  • Hi Pattnaik, This is what I get when I check the website source: Am I missing something there?? Commented Sep 29, 2019 at 2:09
  • <!DOCTYPE html> <html> <head> <title>Central Cinema</title> <link rel="stylesheet" href="maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> <link rel="stylesheet" type="css" href="/css/styles.css"> </head> <body> <div class="container"> <div class="landing-header"> <h1>Search For a Movie</h1> <form action="/results" method="GET"> <input type="text" placeholder="search term" name="search"> <input type="submit"> </form> </div> </div> </body> </html> Commented Sep 29, 2019 at 2:11

1 Answer 1

1
<link rel="stylesheet" href="/css/styles.css"/>

Just remove the type="css" from link

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.