Error 404: CSS3 file not found - - utilizing Node.JS and EJS

While it may appear similar to previous inquiries, I have explored other solutions without success. Below is my code snippet:

NodeJs:

var express = require("express"),
    app     = express(),
    mongoose = require("mongoose");

mongoose.connect("mongodb://localhost/e_c");

app.use(express.static(__dirname+"public"));
app.use(express.static(__dirname+"partials"));

var blogSchema = new mongoose.Schema({
  title: String,
  author: String,
  pictureForTitle: String,
  content: String
});

var blog = mongoose.model("blog",blogSchema);

app.set("view engine","ejs");

  app.get("/",function(req,res){
    res.render("home");
  });

  app.listen(process.env.PORT,process.env.IP);

Head.ejs:

<html>
<head>
    <link rel="stylesheet" type="text/css" href="/public/css/styles.css">
</head>
<body>
<nav id="navBar">
    <div id="aboutSite">
        <p>About This Site</p>
        <div id="aSDropContent">
            <p>About The Author Of This Site</p>
            <p>Why The Author Created This</p>
        </div>
    </div>
</nav>

I've attempted using express.static as shown in the code above, but it's not yielding the desired outcome. I even tried referencing a previous project for guidance.

Sincerely, Josh C.

Answer №1

I encountered a similar problem and managed to resolve it by substituting "public" with "/public" in my code.

app.use(express.static(__dirname+"/public"));

Additionally, I made adjustments to the following:

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

Any ideas on how to accomplish this task using CSS?

Is there a way to align 4 divs side by side with widths that adjust automatically based on the user's monitor resolution? Even if I have 16 divs, I still want only 4 to be visible at a time. I initially tried assigning percentages to each div, but i ...

Navigating AngularJS UI router with dot (.) character explained

I need help with handling a dot character in a URL pattern for a state function. www.test.com/search.go?param=test It seems that the dot character is not being handled properly by the angularjs UI router. How can I manage this dot character correctly? ...

Why is my JSON object showing up as undefined in my Node.js POST request?

I have a CentOS server that is currently running a node.js HTTP server (code provided below). My goal is to pass JSON data from the command line by using the following CURL command: curl -X POST -H "application/json" -d '{"val1":"hello","val2":"my"," ...

Arrangements of lines in website design for various screen resolutions

I am having an issue with the layout I'm working on - specifically, there is a visible outline of the div boxes at certain resolutions or when zooming in. This is what it should look like: However, this is how it appears at some resolutions or when ...

Utilize the populate() method to access data from two distinct schemas in MongoDB

I am working with two MongoDB collections: comments var mongoose = require('mongoose'); var CommentSchema = new mongoose.Schema({ body: String, author: String, upvotes: {type: Number, default: 0}, post: { type: mongoose.Schema.Types.Ob ...

Issue with displaying Git remote repository on list item element (ul) not appearing

My attempt to showcase my GitHub repositories via their API is not displaying on my webpage, even though the exact same code works perfectly fine here on JSFiddle Upon debugging, it seems that the script is being invoked but the content is not loading wit ...

Clear out a collection in backbone.js

I am looking to clear out a collection by removing each item in sequence. this.nodes.each(function(node){ this.nodes.remove(node); }, this); The current method is ineffective as the collection length changes with each removal. Utilizing a temporary arr ...

Joomla CSS styling malfunctioning

I've been exploring the creation of an in line menu using Joomla 1.6 and CSS. The issue arises when Joomla removes <span class="dmenu"> from the document before saving, despite having all cleanup options turned off. This led me to try a couple ...

Ways to obtain the index of a button

Once upon a time, I used to create a plethora of buttons using a for loop. The title[] array was filled with numerous values. export const renderButtons1 = (numOfBtns,title,navigate) => { const views1 = []; for ( var i = 0; i < numOfBtns; ...

leveraging asynchronous functions in Meteor version 1.3 and beyond

Hey everyone, I am interested in utilizing the Async NPM package along with the eachLimit function within Meteor 1.3+. Previously, I successfully used it without Meteor as shown below: var items = ["test", "test2","test3","test4","test5","test6","test7"," ...

What is the best way to implement a toggle feature for a single image within a div element that contains multiple images when clicked?

I am facing an issue where I have multiple images stacked on top of each other. When one of the images is clicked, I want a toggle function to activate that changes the opacity of the top image to 0, revealing the image underneath. However, every time I cl ...

Prevent req.flash from clearing data in middleware operations

I am currently using connect-flash along with express to manage flash messages. However, I have encountered an issue where the messages are deleted once they are read for the first time. Here is an example: Setting a flash message: req.flash("myMessa ...

Create a 3D visual display with the use of three.js in Javascript

I'm navigating my second round with three.js and have been experimenting for a good 3 hours. However, I seem to be at a loss when it comes to determining my next steps. My goal is to create something similar to the layout found here: I've manag ...

npm places modules in the user's personal directory

When using the command npm install <module>, modules are always installed in the user's home directory by default. What setting causes this behavior? I want to be able to install modules to the current path instead. For example, when I try to in ...

unable to successfully execute jQuery popup close functionality

I have a button on my mobile site that I want to function as follows: Upon clicking the button, a popup should appear with text and an OK button. When the OK button is clicked, the popup should disappear without affecting the page. My code for this functi ...

What is the best way to dynamically generate a consistent margin or padding between two sections on different screen sizes?

I have successfully stacked two sections on top of each other. To achieve this layout, I utilized position:relative on the parent container div and then employed position:absolute on the child divs to align them based on the parent container's top pos ...

The issue with Facebook Node Passport not retrieving the email address has been identified

Hello everyone, I've been searching in various places and also here Issue with Missing Email Key During User Authentication https://github.com/jaredhanson/passport-facebook/issues/134 I have included the standard passport Facebook code. I have speci ...

Tips for achieving a uniform border in Bootstrap's input-group when adding an image

I am working on creating a search box within a navbar and encountering an issue with the border style: https://i.sstatic.net/DCMpX.png My challenge lies in achieving consistent borders - I aim for the icon to have the same border as the "Search..." box w ...

What is the most effective method for disregarding undefined values?

Implementing a project using Vue.js and Vuex, I am retrieving data from an API that functions as a content-management system. The product class in the CMS possesses numerous properties that can be populated by the user, such as; { "title": &quo ...

Having issues with Angular http.post not sending data when using subscribe

I'm currently facing an issue with sending data to my API using post.subscribe. Despite the fact that no errors are being thrown, the data is not being sent successfully. It's important to note that the API itself is functioning perfectly. Belo ...