Express Node.js Routing Issue

xKlydez

I am building a website using Express and NodeJS. However I am facing this routing issue. This is my route I'm using in my app.js, which is expecting a parameter.

app.get(['/purchase/:purchaseID',], getPurchasePage)

And the route will link to:

res.render('purchase.ejs' , {
        title: "Purchase Order :" + req.param.referenceID,
        referenceID : req.param.referenceID
    })

However, upon accessing the link via e.g. (localhost:2000/purchase/123456), the page loads. However all external files (CSS/JavaScript/JQuery) could not be loaded.

This led me to think that there is something going on with this line of code instead:

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

I tried fiddling with the my routes and I managed to get it completely working with the website loading fine

app.get(['/purchase?id=:purchaseID',], getPurchasePage)

However, I would really like to use the first method I mentioned. Would like to get some help on the above.

Thanks!

Jordan

I tried it and it works

head.ejs

<link rel="stylesheet" href="/js/app.js">

app.js

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

Maybe you're using a relative path like js/jquery.js and not /js/jquery.js

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related