CSS stylesheet causing syntax errors in node.js application

110 Views Asked by At

I'm trying to load a css file into my node.js application however it causes syntax errors in my application.

here is my css file called "style.css" under an assets folder

.like__btn {
    padding: 10px 15px;
    background: #0080ff;
    font-size: 18px;
    font-family: "Open Sans", sans-serif;
    border-radius: 5px;
    color: #e8efff;
    outline: none;
    border: none;
    cursor: pointer;
  }

here is my index.js server file where I load my static files

app.use('/assets', express.static('./assets'));

here is where the stylesheet is included in my ejs files

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link rel="stylesheet" href="./assets/style.css" type="text/css">
  <!--<link rel="stylesheet" href="style.css" type="text/css">-->
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Blog</title>
</head>

here is the error message I get

C:\Users\sukho\Desktop\databasemidterm\assets\style.css:2
.like__btn {
^

SyntaxError: Unexpected token '.'
1

There are 1 best solutions below

0
On

If your CSS file is directly in the public folder and your EJS file is in the views folder, you could use:


HTML
<link rel="stylesheet" href="../assets/style.css" type="text/css">