Im working on node.js(express) with ejs and im not able to include a .css file to it It browser shows the following error.
localhost/:1 Refused to apply style from
'http://localhost:3000/posts/app.css' because its MIME type
('text/html') is not a supported stylesheet MIME type, and strict MIME
checking is enabled.
My app.js goes thus:
var express = require('express');
var app = express();
app.use(express.static("public"));
app.get("/",function(req,res){
res.render("home.ejs");
});
app.get("/posts",function(req,res){
var posts = [
{title : "Post 1",author : "Malinda"},
{title : "Hello Sri Lankda",author : "Supun"},
{title : "Hello World",author : "Gokula"}
]
res.render("posts.ejs",{posts : posts});
});
app.listen(3000,function(){
console.log("Server Started");
});
and posts.ejs file
<link rel="stylesheet" type="text/css" href="app.css">
<h1>The Post Page</h1>
<p>Using For Loop</p>
<% for(var i =0; i < posts.length; i++){ %>
<li>
<%= posts[i].title%> - <strong><%= posts[i].author%></strong>
</li>
<% } %>
<br><br>
<p>Using For Each Loop</p>
<% posts.forEach(function(post){ %>
<li>
<%= post.title%> - <strong><%= post.author%></strong>
</li>
<% }) %>
and css file
body{
background : yellow;
color : red;
}
please any one heip me to figure out what went wrong