Unlinked CSS File in NodeJs To-Do List

I'm working on a Todo List project using nodeJs, and I'm struggling to connect the CSS file. I've added the CSS file in header.ejs and included it in list.ejs file, but for some reason, the CSS file is still not being linked properly.

Answer №1

One effective approach to accomplish this is by following these steps. Initially, you should establish a public folder within your root application. Subsequently, create a css folder inside the public folder and then proceed to create any desired css file within it. The directory structure should resemble the following:

public > css > file.css

Following that, navigate to your app.js file and incorporate the following code snippet:

const path = require('path');
const express = require('express');


app.use(express.static(path.join(__dirname, 'public')))

After completing the aforementioned steps, you can seamlessly link your css file to any ejs file utilizing the following syntax as an example:

<link rel="stylesheet" href="/css/main.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

Is it possible to generate a basic HTML page using Express JS without utilizing Ejs or any other templating engine

I have a basic HTML file with a Bootstrap form, along with a simple API coded within. In my server.js file, I've specified that when I request /about, it should redirect me to the about.html page. However, instead of redirecting, I'm encountering ...

How does the use of nodejs, a server-side scripting language, tie into ReactJs or other front-end languages?

Can Node, being a server-side scripting language, be effectively utilized in the development of front-end applications such as npx create-react-app or npx create-nuxt-app? ...

Warning: MaxListenersExceededNotification may occur during the installation or creation of Node.js projects on macOS

Encountering a warning message while attempting to set up or generate Node.js projects on macOS (darwin): (node:80101) MaxListenersExceededWarning: Possible EventEmitter memory leak detected. 11 close listeners added to [TLSSocket]. Use emitter.setMaxList ...

Error encountered when attempting to install a module using npm: "tunneling socket

Having trouble installing nodejs modules using npm on Windows while behind a proxy? Here is how I set up the proxy: npm config set proxy internet.cp:8080 npm config set proxy-http internet.cp:8080 Unfortunately, when attempting to install a packet, I enc ...

Asynchronous NestJs HTTP service request

Is there a way to implement Async/Await on the HttpService in NestJs? The code snippet below does not seem to be functioning as expected: async create(data) { return await this.httpService.post(url, data); } ...

Configuring nodejs cluster with socket.io and nginx

I've set up a nodejs cluster using the socket.io library and am routing requests through an nginx server. While websocket connections are functioning well in most cases, I'm facing issues with polling as a transport protocol in socket.io. Here&a ...

Having trouble with the npm build command - getting an error message saying "npm-build.html not found"

I'm encountering an issue where "npm build" is not working because it's searching for a file that no longer exists. PS C:\Users\simon\Desktop\3-Projects\1-Coding\simon\simon> npm build npm ERR! code 1 npm ERR ...

Leveraging node.js and coffeescript to execute commands on Ubuntu

For running Ubuntu commands with node.js in coffeescript, I am utilizing child_process.exec. When I run the below commands: list = child_process.exec("ls") print list The output displayed is: [Object Object] Why isn't the expected output of the ls ...

Retrieve a user's geographical location by utilizing the Slack API

I'm currently working on a Slack bot created with the Slack Node.js SDK. One of the tasks I need to accomplish is retrieving the geolocation data or latitude-longitude coordinates of the user. Is there an API or any other feature in Slack that can hel ...

Utilizing GET requests to display varying results from MongoDB queries on a single webpage

I want to enhance my website by adding a search bar in the top section that retrieves a single document (ink) from a mongo database. Additionally, I am looking to display all documents from the same database on the same page. The challenge I am facing is ...

Socket.on seems to be malfunctioning

Currently, I am in the process of creating a message board for practice purposes and have successfully implemented notifications and a chat application using socket.io. My next goal is to add basic video call functionality, but I have encountered some dif ...

The error at core.js line 4442: TypeError - Unable to access the 'trim' property of an undefined value

I encountered an issue with the 'trim' function in my Angular Node MySQL CRUD Application core.js:4442 ERROR TypeError: Cannot read property 'trim' of undefined at AdmissionListComponent.post (admission-list.component.ts:30) at Admissi ...

Building a customised-schema table for storing data with express-mysql-session

I am exploring the option to store the user id in the MySQL Database's sessions table using express-mysql-session. Initially, I set the user id in the middleware as shown below: import "dotenv/config"; import express from "express" ...

Leveraging HTTPOnly Cookie for GET request (Accessing user information from server with user_id cookie)

While I was learning from a tutorial, I encountered an interesting scenario where a user id is stored in an HTTPOnly cookie sent by the backend to the frontend after the user logs in. The challenge, however, is that HTTPOnly cookies cannot be accessed by t ...

Confirming user banking information is necessary solely for account activation through Stripe

I've been working with NodeJS and ExpressJS Is there a way to set up account verification with Stripe? I want to confirm that users have bank accounts without charging them. What kind of information can I access through this verification process? My ...

Strange Actions of Mongoose and Everyauth

Whenever a new user logs in to my website using everyauth for the first time, the following code is executed. It checks if the user exists in my mongodb database and if not, it creates a new entry. However, I am facing an issue where this process works p ...

Which medium is the optimal choice for file manipulation in Node.js and JavaScript?

Is there a simple way for JavaScript to receive incoming data from Node.js that was obtained from an external server? I've been searching for a solution to this problem for days now. Here's my current approach: I plan to have both the server-sid ...

Generating an Array of objects through the use of the each method

Currently, I am in the process of developing a web scraper using node.js along with puppeteer and cheerio. Although I can successfully display the desired strings in the console.log, I am facing challenges in determining if this task is achievable. $(&apo ...

PhoneGap Troubleshooting: Device Plugin Malfunctioning

I'm having trouble getting the device plugin to work with my Cordova/PhoneGap project. Currently, I am using Cordova version 3.3.1-0.1.2. I followed the documentation and installed the plugin using the following command: C:\ProjectFolder>pl ...

Is there a way to attach a file in Mongoose Schema? I tried using String and it worked, but when I tried to use File, I encountered the error "[1]Error: File is not

const mongoose = require('mongoose'); const { Schema } = mongoose; const NoteSchema = new Schema({ user: { type: mongoose.Schema.Types.ObjectId, ref: 'user', }, title: { type: String, required: true, }, attac ...