How to link external css files in a Node.js project

Can I add an external CSS file in node.js using EJS?

I attempted to do so, but encountered difficulties:

app.use('/static', express.static('/view')) 

I included the CSS in EJS like this:

<link rel="stylesheet" type="text/css" href="materialize.scss">

This error keeps appearing:

Refused to apply style from 'http://localhost:8081/static/materialize.scss' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.

Answer №1

It's important to convert the scss code into css before using it in a browser as browsers do not understand scss.

npm install --save scss
sass static/materialize.scss static/css/materialize.css

After compiling, include the following link in your HTML:

<link rel="stylesheet" type="text/css" href="/static/css/materialize.css">

I trust this information proves helpful.

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

Issue with Bootstrap grid borders

I am currently working on a grid system that displays flight information in 10 columns, with a select button and price in 2 columns. I am facing an issue where adding a border to separate the select button section from the rest of the flight information on ...

The values entered in the React form inputs are not displaying accurately

I'm currently working on a project that involves creating a form for tours. Everything seems to be working well, except for the issue of input values getting mixed up. For example: Actual output: { tourName: 'pune darshan', location: &apos ...

Using JQuery to eliminate the current div in an image slider

I currently have an image slider that allows users to switch between images. There are two buttons - one adds a new item to the slider, while the other is supposed to remove the current image from the slider, but it doesn't seem to be working properly ...

MongoDB Node.js throws a RangeError when trying to push a message that exceeds the maximum call stack size

I'm currently delving into the world of building a MEAN app and encountering an issue when attempting to append a message to a messages array within my User Model. While I can successfully create a new message and pass the user object, I face an error ...

How can you use the transform property in CSS to rotate the dropdown arrow by 180 degrees and move it vertically by 2 pixels?

gradeexpanded:false, gradeOnClick: function (event) { this.gradeexpanded = !this.gradeexpanded; }, .dropdown-check-list { margin-left: 35px; displa ...

Defining Higher Order Components in ReactJS: A comprehensive guide

Trying to wrap my head around Higher Order Components (HOC) in ReactJS with this simple example... I've got three files - First.js, Second.js, and App.js. How should I structure these files so that the computations done in the first file can be acces ...

The Walmart MWS API is failing to provide the nextCursor data as expected

Upon reviewing the Walmart Marketplace API for fetching all items available in the catalog, you will notice that it provides: errors (array of objects) itemResponse (array of objects) additionalAttributes (object) totalItems (integer) nextCursor (string) ...

The Node GET method does not support a mixture of constants and strings in the query

I've encountered an issue with combining an environmental variable and a string for an api route. When I try to use them together, it generates an error, but separately they work fine. For example, this code works: app.get(`${api}`,(req, res) => { ...

What is the best way to delete HTML classes that were generated by a function?

Currently, I'm immersed in the Etch A Sketch project as part of my journey through The Odin Project. Using DOM manipulation, I successfully created a grid and displayed it on the screen. Now, my aim is to allow users to resize the grid by removing the ...

Conditional Statements in jQuery

Trying to implement a check for the CSS 'display' property being set to "none", then slideDown the element "menuBK". If not, slideUp "menuBK" but encountering an error in my IF statement. $(document).ready(function(){ $("#burger").click(func ...

Achieve the sticky effect for text in a HTML div using CSS to keep it anchored to the

Seeking advice on how to create a floating box that remains in the bottom right corner of a div using CSS. Any tips or suggestions are appreciated! (Here's an example of what I'm aiming for: https://i.stack.imgur.com/DkD5C.png) ...

Showcasing the Characteristics of Products in a Table on Prestashop

Dealing with PrestaShop. I have configured attributes for a product and I want to showcase them in a table format similar to this example: The table should display the Paper Size across the top, with each row representing the quantity of paper. In my ad ...

The excessive use of Selenium Webdriver for loops results in multiple browser windows being opened simultaneously, without allowing sufficient time for the

Is there a way to modify this code so that it doesn't open 150 browsers to google.com simultaneously? How can I make the loop wait until one browser finishes before opening another instance of google? const { Builder, By, Key, until } = require(& ...

Tips on creating adaptable images for mobile viewing

My coding conundrum involves the use of two columns - one for an image and the other for a description of that image. However, when viewing my site on mobile devices, the image is cut off at only half its height. Adjusting both columns to col-sm-6 results ...

Ubuntu compatibility with chrome-driver 83

Currently using Ubuntu 18.04.1 LTS with Google Chrome version 83 and corresponding chrome-driver version 83 successfully for a while, I recently encountered an issue after updating to the latest stable versions: google-chrome-stable v83.0.4103.61 and chrom ...

regular expression for swapping data

Here is a sample transformation: .city.playground[?(@.playhouse == 'true' && @.IsPoolAvailable=='true')].checked] Can be converted to: .city.poolavailable.checked An attempt at achieving this conversion using regex: result ...

Ways to verify that a javascript function generates an object and executes a method within that object

Currently, I am in the process of updating server code written in nodejs and incorporating unit tests into the mix. However, I have encountered a challenge that I need assistance with: classX.prototype.methodX = function () { // Create new session ...

Creating a border around an SVG element using the background color of its parent container

I am aiming to layer 2 SVGs on top of each other. The top SVG will have an outline to make it stand out more from the bottom SVG. These SVGs are embedded on buttons with transitions and hover colors. I want the outline SVG to match the background color of ...

Using a JSON post with a curl command to authenticate via digest authentication

(Utilizing node.js, express, passport-http) I've set up a POST route with digest authentication for an application-json content type. Strangely, I can successfully access the GET route with digest authentication without any issues. Additionally, the ...

What is the best way to integrate Oracle database with Node.js and Express.js for developing a RESTful API?

I have successfully connected MONGO DB and MYSQL to my RESTFul API using nodejs and express JS, but I am struggling with connecting Oracle. Here is the code for connecting to MySQL: const mysqlConnection=mysql.createConnection({ host:'localhost& ...