Having trouble incorporating CSS into a node/express/pug application

I'm currently working on my first Node application using Express and Pug (formerly Jade). Everything seems to be functioning smoothly, except for getting my CSS files to load in the browser. (I keep receiving a "404 Error: GET" when trying to access http://localhost:3000/css/syles.css)

Here is an outline of my project structure:

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

This is a snippet from 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');

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

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

// Player's bag route
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).json({
              error: e.message
            });
        });
});

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

The content of the bag.pug file:

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

Answer №1

There seems to be a typo: syles instead of styles

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

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Bluebird guarantees - each function

Thank you in advance for your assistance. While working with Bluebird promises, I have a set of promises running. In the final promise, I aim to execute one function multiple times for each object in an array. Here is some pseudocode as an example: var ...

Tips for preserving border-radius while animating the size of an element

I am trying to achieve a carousel indicator animation where the list item pops out to zero radius in a circular shape. However, my current attempt results in the list item animating in a square shape instead. Is there a way to make it appear in a circular ...

Count the number of times an iteration occurs in AngularJS/JavaScript

I need assistance with my code snippet below, as I am trying to determine the count of all instances where $scope.rm is equal to "failed" or when $scope.percentage is less than 50. angular.forEach(result1, function (value, key) { $scope.percentage ...

Issues with Laravel capturing complete request data

In my Laravel project, I am trying to pass select2 multiple select values to the database using AJAX. Previously, I was passing the values through get requests which resulted in all values being shown as URL parameters. However, when checking with a reques ...

The value of e.target in the Datepicker is not defined

I'm utilizing the Datepicker component to allow users to select a date and update the state with their selection. However, I encountered an issue when trying to change the default date using input, as React throws an error message: "TypeError: e.targ ...

Transferring a header across a series of interconnected services

I have a script that calls two services, combines their results, and displays them to the user. The services are: Service 1 (hello) and Service 2 (world), resulting in "Hello world". I want to include an ID in the headers to track the route of the calls. ...

Implementing an input field using JavaScript

I have multiple search forms, each containing an input field with the class "search_input". My goal is to add the following code on button click: <input type="submit" class="searchbtn" value="Search" /> next to each input <input type="text" cl ...

Creating a custom data type with a specific value in GraphQL

I am new to graphQL and have some questions regarding it. After going through the documentation, I decided to build something of my own. Currently, my setup is quite simple. At the beginning of my application, I have the following code: const express = ...

AngularJS is used to vertically collapse three different div elements. This feature

I am facing an issue with the design of my page that contains three panels. Two of these panels have tables, and when viewing the page on a smaller display, it disrupts the layout. I am wondering if there is a way to add collapsible buttons to the panels s ...

Issue with Angular Node.js: The output is showing as Undefined, making it difficult to retrieve data from the server

Recently, I delved into the world of Node and Angular programming. I attempted to create a basic application where I could connect my backend (localhost:3000) to my frontend to display data. Surprisingly, when I stored the data received from the server as ...

Inline CSS for altering the appearance of text within a DIV container

Within the confines of this DIV element... <div name="layer1" style="background-color:lightblue;"> <hr>Site:Downtown DataCenter Device: 2KBS</hr> </div> Hello there, I am utilizing Inline CSS Styling. Is it possible to make the t ...

Unable to choose anything within a draggable modal window

Can someone please assist me? I am struggling to figure this out. I can't select text inside the modal or click on the input to type text into it. I suspect it may be due to z-index issues, but I'm having trouble locating them. var currentZ = n ...

Saving vast array in MongoDB

I am currently working on a personal project that involves implementing a search feature. My setup includes using typeahead.js with a REST api created in expressJS and mongoDB. I could use some guidance on two particular challenges I am facing. While my ba ...

Prevent the line from crossing over the circle in CSS

How can I prevent the line from intersecting the circle? I want the line to be outside the circle. The background (in this case, of the li tag) will be transparent. #project-wrapper { width: 100%; /* Adjusting the position of the element on the pa ...

Issue with iPad - Pop-up appearing underneath the overlay

I've implemented a custom bootstrap modal that works well on Desktops and Mobile devices. However, I encountered an issue when trying to open it on an iPad. The modal opens but is completely obscured by a black overlay with opacity. The content of th ...

There is a parse error that shows up while trying to retrieve the JSON array using jQuery

I have been struggling with a problem for hours and I can't seem to find the solution. I am working with a JSON array file and trying to retrieve the array in jQuery, but I keep getting a parse error. Here is my code: var obj=[ { id : 1, ...

personalize auto-suggestions in AngularJS

Here is a link to a custom search implementation using autocomplete in angularjs. Is it possible to modify this so that the matching starts from the first character? HTML <div ng-app='MyModule'> <div ng-controller='DefaultCtrl& ...

What sets apart route.use(), route.all(), and route.route() in Express?

Is it possible to replace router.all() with router.use() if the former just matches all methods? Also, what are the differences between using router.use() and router.route()? ...

Reading JSON arrays with JQuery

I have a RESTful web service located at http:// localhost:8080/CRUDWebAppMavenized/persons that returns a JSON array. I am using jQuery AJAX to fetch the data and display it in an HTML table, but I'm having trouble getting it to show up properly. Belo ...

Developing React components in TypeScript in a dynamic manner

Is there a way to dynamically create components using React and TypeScript? If I have a RandomComponent and pass it as props to renderInput, how can I return <RandomComponent>? This snippet of code doesn't seem to work: export const renderInput ...