0

My folders:

server.js
index.html
-public
 --css
  --ses.scss
  --style.css

Server js:

var express = require('express');
    var path = require('path');
    var publicPath = path.resolve(path.join(__dirname, 'public'));
    var app = express();
    var http = require('http').Server(app);
    var fs = require('fs');

    app.use(express.static(path.join(__dirname, 'public')));
    app.get('/', function (req, res) { 
        res.sendfile('./index.html');

    });
http.listen(3000, function () {
    console.log('listening on *:3000');
});

Index.html:

<link rel="stylesheet" type="text/css" href="/public/css/ses.scss">
<link rel="stylesheet" type="text/css" href="/public/css/style.css">

CSS works when I open index.html with google chrome without server.When I use node.js CSS isn't loading.

1
  • I don't think an scss file can be loaded directly into html Commented Nov 20, 2017 at 20:41

2 Answers 2

1

express.static() serves the contents of its folder directly on the root.

Therefore, public/ is not part of the URL.

Sign up to request clarification or add additional context in comments.

2 Comments

So, how can I fix the problem?
@dandadadadan: Use a path relative to the directory (/css/...).
0

Node :

app.use("/css",express.static(path.join(__dirname, 'public/css')));

css :

<link rel="stylesheet" type="text/css" href="/css/ses.scss">
<link rel="stylesheet" type="text/css" href="/css/style.css">

1 Comment

Welcome Bro :) .

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.