CSS seems to be sent to page, but nothing applies [ExpressJS + Handlebars]











up vote
1
down vote

favorite












I am attempting to do a very simple page with Handlebars and Express with NodeJS, however I am running into difficulty getting it to display css. It seems that the browser is receiving the CSS file given the feedback and the 200 code I'm getting in my Node window, but no effect is shown on the actual page.



file structure



app.js
/public
/stylesheets
style.css
/views
/layouts
main.handlebars
home.handlebars


app.js



var express = require('express');
var exphbs = require('express-handlebars');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');


app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/', express.static(path.join(__dirname, '/public')));


var person = {
name:"Clay",
age:"20",
attr:["tall","handsome","wearing a red sweater"]
}


app.get('/', function (req, res, next) {
res.render('home', {layout: false, people: person});
});

module.exports = app;


main.handlebars



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Database</title>
<link rel="stylesheet" href="stylesheets/style.css" />
</head>
<body>
{{{body}}}

</body>
</html>


home.handlebars



<h1>Example App: Home</h1>

hello world


style.css



body {
background-color: red;
}


node console
enter image description here










share|improve this question






















  • can you try to change app.use('/', express.static(path.join(__dirname, '/public'))); to app.use('/public',express.static(path.join(__dirname, '/public'))); and see.
    – xan_z
    Nov 5 at 3:09












  • does not appear to work @xan_z
    – clbx
    Nov 5 at 3:32












  • Okay, also update the HTML template from <link rel="stylesheet" href="stylesheets/style.css" /> to <link rel="/public/stylesheet" href="stylesheets/style.css" />.. this is what I have and it works. I use ejs thou..
    – xan_z
    Nov 5 at 15:22















up vote
1
down vote

favorite












I am attempting to do a very simple page with Handlebars and Express with NodeJS, however I am running into difficulty getting it to display css. It seems that the browser is receiving the CSS file given the feedback and the 200 code I'm getting in my Node window, but no effect is shown on the actual page.



file structure



app.js
/public
/stylesheets
style.css
/views
/layouts
main.handlebars
home.handlebars


app.js



var express = require('express');
var exphbs = require('express-handlebars');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');


app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/', express.static(path.join(__dirname, '/public')));


var person = {
name:"Clay",
age:"20",
attr:["tall","handsome","wearing a red sweater"]
}


app.get('/', function (req, res, next) {
res.render('home', {layout: false, people: person});
});

module.exports = app;


main.handlebars



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Database</title>
<link rel="stylesheet" href="stylesheets/style.css" />
</head>
<body>
{{{body}}}

</body>
</html>


home.handlebars



<h1>Example App: Home</h1>

hello world


style.css



body {
background-color: red;
}


node console
enter image description here










share|improve this question






















  • can you try to change app.use('/', express.static(path.join(__dirname, '/public'))); to app.use('/public',express.static(path.join(__dirname, '/public'))); and see.
    – xan_z
    Nov 5 at 3:09












  • does not appear to work @xan_z
    – clbx
    Nov 5 at 3:32












  • Okay, also update the HTML template from <link rel="stylesheet" href="stylesheets/style.css" /> to <link rel="/public/stylesheet" href="stylesheets/style.css" />.. this is what I have and it works. I use ejs thou..
    – xan_z
    Nov 5 at 15:22













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I am attempting to do a very simple page with Handlebars and Express with NodeJS, however I am running into difficulty getting it to display css. It seems that the browser is receiving the CSS file given the feedback and the 200 code I'm getting in my Node window, but no effect is shown on the actual page.



file structure



app.js
/public
/stylesheets
style.css
/views
/layouts
main.handlebars
home.handlebars


app.js



var express = require('express');
var exphbs = require('express-handlebars');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');


app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/', express.static(path.join(__dirname, '/public')));


var person = {
name:"Clay",
age:"20",
attr:["tall","handsome","wearing a red sweater"]
}


app.get('/', function (req, res, next) {
res.render('home', {layout: false, people: person});
});

module.exports = app;


main.handlebars



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Database</title>
<link rel="stylesheet" href="stylesheets/style.css" />
</head>
<body>
{{{body}}}

</body>
</html>


home.handlebars



<h1>Example App: Home</h1>

hello world


style.css



body {
background-color: red;
}


node console
enter image description here










share|improve this question













I am attempting to do a very simple page with Handlebars and Express with NodeJS, however I am running into difficulty getting it to display css. It seems that the browser is receiving the CSS file given the feedback and the 200 code I'm getting in my Node window, but no effect is shown on the actual page.



file structure



app.js
/public
/stylesheets
style.css
/views
/layouts
main.handlebars
home.handlebars


app.js



var express = require('express');
var exphbs = require('express-handlebars');
var path = require('path');
var cookieParser = require('cookie-parser');
var logger = require('morgan');

var indexRouter = require('./routes/index');
var usersRouter = require('./routes/users');

var app = express();

app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');


app.use(logger('dev'));
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(cookieParser());
app.use('/', express.static(path.join(__dirname, '/public')));


var person = {
name:"Clay",
age:"20",
attr:["tall","handsome","wearing a red sweater"]
}


app.get('/', function (req, res, next) {
res.render('home', {layout: false, people: person});
});

module.exports = app;


main.handlebars



<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Database</title>
<link rel="stylesheet" href="stylesheets/style.css" />
</head>
<body>
{{{body}}}

</body>
</html>


home.handlebars



<h1>Example App: Home</h1>

hello world


style.css



body {
background-color: red;
}


node console
enter image description here







javascript node.js express handlebars.js






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 5 at 1:48









clbx

248




248












  • can you try to change app.use('/', express.static(path.join(__dirname, '/public'))); to app.use('/public',express.static(path.join(__dirname, '/public'))); and see.
    – xan_z
    Nov 5 at 3:09












  • does not appear to work @xan_z
    – clbx
    Nov 5 at 3:32












  • Okay, also update the HTML template from <link rel="stylesheet" href="stylesheets/style.css" /> to <link rel="/public/stylesheet" href="stylesheets/style.css" />.. this is what I have and it works. I use ejs thou..
    – xan_z
    Nov 5 at 15:22


















  • can you try to change app.use('/', express.static(path.join(__dirname, '/public'))); to app.use('/public',express.static(path.join(__dirname, '/public'))); and see.
    – xan_z
    Nov 5 at 3:09












  • does not appear to work @xan_z
    – clbx
    Nov 5 at 3:32












  • Okay, also update the HTML template from <link rel="stylesheet" href="stylesheets/style.css" /> to <link rel="/public/stylesheet" href="stylesheets/style.css" />.. this is what I have and it works. I use ejs thou..
    – xan_z
    Nov 5 at 15:22
















can you try to change app.use('/', express.static(path.join(__dirname, '/public'))); to app.use('/public',express.static(path.join(__dirname, '/public'))); and see.
– xan_z
Nov 5 at 3:09






can you try to change app.use('/', express.static(path.join(__dirname, '/public'))); to app.use('/public',express.static(path.join(__dirname, '/public'))); and see.
– xan_z
Nov 5 at 3:09














does not appear to work @xan_z
– clbx
Nov 5 at 3:32






does not appear to work @xan_z
– clbx
Nov 5 at 3:32














Okay, also update the HTML template from <link rel="stylesheet" href="stylesheets/style.css" /> to <link rel="/public/stylesheet" href="stylesheets/style.css" />.. this is what I have and it works. I use ejs thou..
– xan_z
Nov 5 at 15:22




Okay, also update the HTML template from <link rel="stylesheet" href="stylesheets/style.css" /> to <link rel="/public/stylesheet" href="stylesheets/style.css" />.. this is what I have and it works. I use ejs thou..
– xan_z
Nov 5 at 15:22

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147312%2fcss-seems-to-be-sent-to-page-but-nothing-applies-expressjs-handlebars%23new-answer', 'question_page');
}
);

Post as a guest





































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53147312%2fcss-seems-to-be-sent-to-page-but-nothing-applies-expressjs-handlebars%23new-answer', 'question_page');
}
);

Post as a guest




















































































這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini