title: express.static not working. Cant get images
body: <p>So, I am trying to access images from my uploads folder but getting following error:
  <a href="https://i.stack.imgur.com/fUZ2a.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fUZ2a.png" alt="enter image description here" /></a></p>
  <p>I have added <code>express.static(root, [options])</code> to my <strong>server.js</strong> here is the source code.</p>
  <pre><code>require(&quot;dotenv&quot;).config({
    path: &quot;C:/Users/dogra/Documents/Web Development/Portfolio/FullStack/market/.env&quot;,
  });
  const path = require(&quot;path&quot;);
  const express = require(&quot;express&quot;);
  const connectDB = require(&quot;./config/db&quot;);
  connectDB();
  const app = express();
  app.use(express.json());
  
  // Express Static Middleware
  const staticPath = path.join(__dirname, &quot;../uploads&quot;);
  app.use(express.static(staticPath));
  
  // Routes
  const productRoutes = require(&quot;./routes/productRoutes&quot;);
  const userRoutes = require(&quot;./routes/userRoutes&quot;);
  const orderRoutes = require(&quot;./routes/orderRoutes&quot;);
  const uploadRoutes = require(&quot;./routes/uploadRoutes&quot;);
  
  app.use(&quot;/api&quot;, productRoutes);
  app.use(&quot;/api/users&quot;, userRoutes);
  app.use(&quot;/api/orders&quot;, orderRoutes);
  app.use(&quot;/api/upload&quot;, uploadRoutes);
  
  app.get(&quot;/api/config/paypal&quot;, (req, res) =&gt;
    res.send(process.env.PAYPAL_CLIENT_ID)
  );
  
  // uploads to &quot;/uploads&quot; folder
  app.use(&quot;/uploads&quot;, express.static(path.join(__dirname, &quot;/uploads&quot;)));
  
  // Check's If the route is not defined and passes 404 error
  app.use((req, res, next) =&gt; {
    const error = new Error(`Requested URL: ${req.path} not found!`);
    error.status = 404;
    next(error);
  });
  
  // Error handler
  app.use((error, req, res, next) =&gt; {
    res.status(error.status || 500);
    res.json({
      error: {
        success: false,
        status: error.status || 500,
        message: error.message,
      },
    });
  });
  
  const PORT = process.env.PORT || 5000;
  app.listen(
    PORT,
    console.log(`Server running in ${process.env.NODE_ENV} on port ${PORT}`)
  );
  </code></pre>
  <p>My file directory looks like this:
  <a href="https://i.stack.imgur.com/6kTdi.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/6kTdi.png" alt="enter image description here" /></a></p>
  <p>Also, I console.log <code>staticPath</code> it is pointing to right directory. What I am doing wrong? Please Help. Thanks in advance.</p>