Sunday, 19 March 2017

Nodejs Express - Why won't my static file be served?

Ive been looking a all kind of posts and just can't understand my mistake. Whatever I do, my css file is just not being served.Does anyone know why?

test/server/app.js:

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

            app.use(express.static(path.join(__dirname, 'public')));
            app.use(express.static(path.join(__dirname, 'browser')));
            var PORT = process.env.PORT || 1337;
            app.listen(PORT, function() {
                console.log('Server is listening!');
            });

test/browser/index.html:

            <head>
                <base href="/" />
                <title>Test</title>
                <link rel="stylesheet" type="text/css" href="public/style.css" />
                <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.1/angular.min.js"></script>

                <script src="app.js"></script>
                <script src="js/app.controller.js"></script>
            </head>

            <body>
                <p>hello world</p>

            </body>
            </html>

My css file is in test/public/style.css



via javascript2016

No comments:

Post a Comment