Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

111
Views
node.js/express javascript route css problem

So i have a problem. I want to make a route for example from localhost.../cars to localhost../bmw/x1

I have a button on localhost../cars, after clicking it, site loads localhost../bmw/x1

So have have this code in my javascript:

const express = require("express");


var app = express();


app.use(express.static("public"));


app.set("views", "views");
app.set("view engine", "pug");

app.get('/', (req, res) => {
    res.render("firstpage");
});


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


app.get("/bmw/x1", function(req,res){
  res.render("bmwx1");
});

app.listen(PORT, function() {
  console.log("server is running);
});

and this in my pug where the firstpage is:(only a piece of the code)

html 
    head 
        link(rel="stylesheet", href="styles/style.css")
        link(href="https://fonts.googleapis.com/css2?family=Akshar:wght@300&display=swap" rel="stylesheet")
        meta(name="viewport", content="width=device-width, initial-scale=1, maximum-scale=1")
    body
        nav 
            h3 
                a(href="/cars") cars

and then on /cars i have somewhere a button:

div
   button(class="detailsbutton") 
          a(href="/bmw/x1") Details

Now this actually works for me, it loads the pug but if i load into localhost../bmw/x1 my css doesn't work there, only on this path, anywhere it works but not there, so it's not formatted.

So im not sure if i can't just use app.get("/site/secondsite",...) and i have to do this other way or a error is somewhere else

Thanks for answering and sorry for my english!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!