javascript - Can't get css in nodeexpresspug app - Stack Overflow

I'm creating my first Node app using Express and Pug (former Jade).Everything is working fine, ex

I'm creating my first Node app using Express and Pug (former Jade). Everything is working fine, except getting my css files running on the browser. (Error 404: GET http://localhost:3000/css/syles.css)

Project structure:

server.js
views
    bag.pug
public
    css
      styles.css

My server js file:

const pug = require('pug');
const path = require('path');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;

const inv = require('./api/pogoni/inventory');

// Set views path
app.set('views', path.join(__dirname, 'views'));
// Set public path
app.use(express.static(path.join(__dirname, 'public')));
// Set pug as view engine
app.set('view engine', 'pug');

// Player's index
app.get('/player', (req, res) => {
    res.render('player', {
        title: 'PLAYER Dashboard'
    });
});

// Player's bag
app.get('/bag', (req, res) => {
    inv.getInventory()
        .then((inventory) => {
            if(!inventory) {
                throw new Error('Unable to fetch inventory.');
            }
            res.render('bag', {
                title: 'PLAYER bag',
                inventory
            });
        })
        .catch((e) => {
            res.status(500, {
              error: e
            });
        });
});

// Start server
app.listen(port, () => {
    console.log(`Server is up on port ${port}`);
});

bag.pug

doctype html
html
    head
        meta(charset='UTF-8')
        title #{title}
        link(rel='stylesheet', href='/css/syles.css')

I'm creating my first Node app using Express and Pug (former Jade). Everything is working fine, except getting my css files running on the browser. (Error 404: GET http://localhost:3000/css/syles.css)

Project structure:

server.js
views
    bag.pug
public
    css
      styles.css

My server js file:

const pug = require('pug');
const path = require('path');
const express = require('express');
const app = express();
const port = process.env.PORT || 3000;

const inv = require('./api/pogoni/inventory');

// Set views path
app.set('views', path.join(__dirname, 'views'));
// Set public path
app.use(express.static(path.join(__dirname, 'public')));
// Set pug as view engine
app.set('view engine', 'pug');

// Player's index
app.get('/player', (req, res) => {
    res.render('player', {
        title: 'PLAYER Dashboard'
    });
});

// Player's bag
app.get('/bag', (req, res) => {
    inv.getInventory()
        .then((inventory) => {
            if(!inventory) {
                throw new Error('Unable to fetch inventory.');
            }
            res.render('bag', {
                title: 'PLAYER bag',
                inventory
            });
        })
        .catch((e) => {
            res.status(500, {
              error: e
            });
        });
});

// Start server
app.listen(port, () => {
    console.log(`Server is up on port ${port}`);
});

bag.pug

doctype html
html
    head
        meta(charset='UTF-8')
        title #{title}
        link(rel='stylesheet', href='/css/syles.css')
Share Improve this question asked Dec 9, 2016 at 1:03 nipnip 1,7071 gold badge12 silver badges21 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 4

You have a typo: syles instead styles

doctype html
html
    head
        meta(charset='UTF-8')
        title #{title}
        link(rel='stylesheet', href='/css/styles.css')

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744970251a4603925.html

相关推荐

  • javascript - Can't get css in nodeexpresspug app - Stack Overflow

    I'm creating my first Node app using Express and Pug (former Jade).Everything is working fine, ex

    1天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信