[Fixed] Unable to display images in Bootstrap 5 navbar using Node.js, Express, and EJS


I’m trying to build a site using express/node.js/ejs
I’m having a hard time with building a navbar using Bootstrap 5.0
In the app.js I have included express.static:


My navbar partial looks like this:

<nav class="navbar navbar-expand-sm sticky-top navbar-light bg-light">
<div class="container-fluid">
    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNavDropdown"
        aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
        <span class="navbar-toggler-icon"></span>
    <div class="collapse navbar-collapse" id="navbarNavDropdown">
        <ul class="navbar-nav mx-auto">
            <li class="nav-item">
                <a class="nav-link active" aria-current="page" href="#">Home</a>
            <li class="nav-item dropdown">
                <a class="nav-link dropdown-toggle" href="#" id="navbarDropdownMenuLink" role="button"
                    data-bs-toggle="dropdown" aria-expanded="false">
                <ul class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
                    <li><a class="dropdown-item" href="#">1</a></li>
                    <li><a class="dropdown-item" href="#">2</a></li>
                    <li><a class="dropdown-item" href="#">3</a></li>
                <a class="navbar-brand" href="#">
                    <img src="/public/images/logoKP.png" alt="" width="30" height="24">
            <li class="nav-item">
                <a class="nav-link" href="#">4</a>
            <li class="nav-item">
                <a class="nav-link" href="#">5</a>

My file structure:

  • public
    • images
      • logoKP.png
  • views
    • partials
      • navbar.ejs
  • app.js

Under chrome I receive 404 for the img. CSS connected the same way works just fine.
Please help. I’m still learning.


You don’t need to include /public in your path. If everything else is correct this should work :

<img src="/images/logoKP.png" alt="" width="30" height="24">

Leave a Reply

(*) Required, Your email will not be published