express.js中CSS未加载,但HTML加载了。

huangapple go评论89阅读模式
英文:

express.js css not loading but html does

问题

文件夹和文件
server.js 这是我目前创建的内容

//导入包
const express = require('express');
const admin = require('firebase-admin');
const bcrypt = require('bcrypt');
const path = require('path');

//声明静态路径
let staticPath = path.join(__dirname, "js");

//初始化 express.js
const app = express();

//中间件
app.use(express.static(staticPath));

//路由
//主页路由
app.get("/", (req, res) => {
    res.sendFile(path.join(staticPath, "index.html"));
})

//注册路由
app.get("/signup", (req, res) => {
    res.sendFile(path.join(staticPath, "signup.html"));
})

// 404 路由
app.get("/404", (req, res) => {
    res.sendFile(path.join(staticPath, "404.html"));
})

app.use((req, res) => {
    res.redirect('/404');
})

app.listen(3000, () => {
    console.log('listening on port 3000.......');
})

index.html 这是我目前创建的内容

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edga">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Clothing - Best Apparels Online Store</title>

        <link rel="stylesheet" type="text/css" href="../css/home.css">
    </head>

    <body>
        <nav class="navbar"></nav>

        <!-- hero section-->

        <header class="hero-section">
            <div class="content">
                <img src="../img/light-logo.png" class="logo" alt="">
                <p class="sub-heading">best fashion collection of all time</p>
            </div>
        </header>

        <!-- card-container-->

        <section class="product">
            <h2 class="product-category">best selling</h2>
            <button class="pre-btn"><img src="../img/arrow.png" alt=""></button>
            <button class="nxt-btn"><img src="../img/arrow.png" alt=""></button>
            <div class="product-container">
                <div class="product-card">
                    <div class="product-image">
                        <span class="discount-tag">50% off</span>
                        <img src="../img/card1.png" class="product-thumb" alt="">
                        <button class="card-btn">add to wishlist</button>
                    </div>
                    <div class="product-info">
                        <h2 class="product-brand">brand</h2>
                        <p class="product-short-des">a short line about the cloth...</p>
                        <span class="price">$20</span><span class="actual-price">$40</span>
                    </div>
                </div>
                <!-- 其他产品卡片 -->
            </div>
        </section>

        <!-- 集合 -->

        <section class="collection-container">
            <a href="#" class="collection">
                <img src="../img/women-collection.png" alt="">
                <p class="collection-title">women <br> apparels </p>
            </a>
            <!-- 其他集合 -->
        </section>
        
        <!-- card-container-->

        <section class="product">
            <h2 class="product-category">Shirts</h2>
            <button class="pre-btn"><img src="../img/arrow.png" alt=""></button>
            <button class="nxt-btn"><img src="../img/arrow.png" alt=""></button>
            <div class="product-container">
                <div class="product-card">
                    <div class="product-image">
                        <span class="discount-tag">50% off</span>
                        <img src="../img/product image 1.png" class="product-thumb" alt="">
                        <button class="card-btn">add to wishlist</button>
                    </div>
                    <div class="product-info">
                        <h2 class="product-brand">brand</h2>
                        <p class="product-short-des">a short line about the cloth...</p>
                        <span class="price">$20</span><span class="actual-price">$40</span>
                    </div>
                </div>
                <!-- 其他产品卡片 -->
            </div>
        </section>
        <!-- card-container-->

        <!-- 其他内容 -->
        <!-- 其他内容 -->
        <!-- 其他内容 -->

        <footer>
            
        </footer>

        <script src="../js/nav.js"></script>
英文:

folder and files
server.js this is what i created so far

//importing packages
const express = require(&#39;express&#39;);
const admin = require(&#39;firebase-admin&#39;);
const bcrypt = require(&#39;bcrypt&#39;);
const path = require(&#39;path&#39;);

//declare static path
let staticPath = path.join(__dirname, &quot;js&quot;);

//intializing express.js

const app = express();

//midlewares
app.use(express.static(staticPath));

//routes
//home route
app.get(&quot;/&quot;, (req, res) =&gt; {
    res.sendFile(path.join(staticPath, &quot;index.html&quot;));
})

//signup route
app.get(&quot;/signup&quot;, (req, res) =&gt; {
    res.sendFile(path.join(staticPath, &quot;signup.html&quot;));
})

// 404 route
app.get(&quot;/404&quot;, (req, res) =&gt; {
    res.sendFile(path.join(staticPath, &quot;404.html&quot;));
})

app.use((req, res) =&gt; {
    res.redirect(&#39;/404&#39;);
})

app.listen(3000, () =&gt; {
    console.log(&#39;listening on port 3000.......&#39;);
})

index.html this is what i created so far

&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta charset=&quot;utf-8&quot;&gt;
&lt;meta http-equiv=&quot;X-UA-Compatible&quot; content=&quot;IE=edga&quot;&gt;
&lt;meta name=&quot;viewport&quot; content=&quot;width=device-width, initial-scale=1.0&quot;&gt;
&lt;title&gt;Clothing - Best Apparels Online Store&lt;/title&gt;
&lt;link rel=&quot;stylesheet&quot; type=&quot;text/css&quot; href=&quot;../css/home.css&quot;&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;nav class=&quot;navbar&quot;&gt;&lt;/nav&gt;
&lt;!-- hero section--&gt;
&lt;header class=&quot;hero-section&quot;&gt;
&lt;div class=&quot;content&quot;&gt;
&lt;img src=&quot;../img/light-logo.png&quot; class=&quot;logo&quot; alt=&quot;&quot;&gt;
&lt;p class=&quot;sub-heading&quot;&gt;best fashion collection of all time&lt;/p&gt;
&lt;/div&gt;
&lt;/header&gt;
&lt;!-- card-container--&gt;
&lt;section class=&quot;product&quot;&gt;
&lt;h2 class=&quot;product-category&quot;&gt;best selling&lt;/h2&gt;
&lt;button class=&quot;pre-btn&quot;&gt;&lt;img src=&quot;../img/arrow.png&quot; alt=&quot;&quot;&gt;&lt;/button&gt;
&lt;button class=&quot;nxt-btn&quot;&gt;&lt;img src=&quot;../img/arrow.png&quot; alt=&quot;&quot;&gt;&lt;/button&gt;
&lt;div class=&quot;product-container&quot;&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card1.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card2.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card3.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card4.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card5.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card6.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card7.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card8.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- collections --&gt;
&lt;section class=&quot;collection-container&quot;&gt;
&lt;a href=&quot;#&quot; class=&quot;collection&quot;&gt;
&lt;img src=&quot;../img/women-collection.png&quot; alt=&quot;&quot;&gt;
&lt;p class=&quot;collection-title&quot;&gt;women &lt;br&gt; apparels &lt;/p&gt;
&lt;/a&gt;
&lt;a href=&quot;#&quot; class=&quot;collection&quot;&gt;
&lt;img src=&quot;../img/men-collection.png&quot; alt=&quot;&quot;&gt;
&lt;p class=&quot;collection-title&quot;&gt;women &lt;br&gt; apparels &lt;/p&gt;
&lt;/a&gt;
&lt;a href=&quot;#&quot; class=&quot;collection&quot;&gt;
&lt;img src=&quot;../img/accessories-collection.png&quot; alt=&quot;&quot;&gt;
&lt;p class=&quot;collection-title&quot;&gt;accessories&lt;/p&gt;
&lt;/a&gt;
&lt;/section&gt;
&lt;!-- card-container--&gt;
&lt;section class=&quot;product&quot;&gt;
&lt;h2 class=&quot;product-category&quot;&gt;Shirts&lt;/h2&gt;
&lt;button class=&quot;pre-btn&quot;&gt;&lt;img src=&quot;../img/arrow.png&quot; alt=&quot;&quot;&gt;&lt;/button&gt;
&lt;button class=&quot;nxt-btn&quot;&gt;&lt;img src=&quot;../img/arrow.png&quot; alt=&quot;&quot;&gt;&lt;/button&gt;
&lt;div class=&quot;product-container&quot;&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/product image 1.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/product image 2.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/product image 3.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/product image 4.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card5.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card6.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card7.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card8.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;!-- card-container--&gt;
&lt;section class=&quot;product&quot;&gt;
&lt;h2 class=&quot;product-category&quot;&gt;Shoes&lt;/h2&gt;
&lt;button class=&quot;pre-btn&quot;&gt;&lt;img src=&quot;../img/arrow.png&quot; alt=&quot;&quot;&gt;&lt;/button&gt;
&lt;button class=&quot;nxt-btn&quot;&gt;&lt;img src=&quot;../img/arrow.png&quot; alt=&quot;&quot;&gt;&lt;/button&gt;
&lt;div class=&quot;product-container&quot;&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card9.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card10.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card11.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card12.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card5.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card6.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card7.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class=&quot;product-card&quot;&gt;
&lt;div class=&quot;product-image&quot;&gt;
&lt;span class=&quot;discount-tag&quot;&gt;50% off&lt;/span&gt;
&lt;img src=&quot;../img/card8.png&quot; class=&quot;product-thumb&quot; alt=&quot;&quot;&gt;
&lt;button class=&quot;card-btn&quot;&gt;add to wishlist&lt;/button&gt;
&lt;/div&gt;
&lt;div class=&quot;product-info&quot;&gt;
&lt;h2 class=&quot;product-brand&quot;&gt;brand&lt;/h2&gt;
&lt;p class=&quot;product-short-des&quot;&gt;a short line about the cloth...&lt;/p&gt;
&lt;span class=&quot;price&quot;&gt;$20&lt;/span&gt;&lt;span class=&quot;actual-price&quot;&gt;$40&lt;/span&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/section&gt;
&lt;footer&gt;
&lt;/footer&gt;
&lt;script src=&quot;../js/nav.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../js/home.js&quot;&gt;&lt;/script&gt;
&lt;script src=&quot;../js/footer.js&quot;&gt;&lt;/script&gt;
&lt;/body&gt;
&lt;/html&gt;

when i run localhost:3000 html does load but css doesnt
what should i do?
i am doing trying to recreate tutorial, but the author doesnt have this problem, nor somebody in the comments, this is the link of the creator https://www.youtube.com/watch?v=yYSfOe0QBOk&amp;list=PLqm86YkewF6S45smPYeNv01aFFKWZSgYD&amp;index=2&amp;ab_channel=ModernWeb

答案1

得分: 1

使用 app.use(express.static(staticPath)); 声明为静态目录的目录不应该是 js 目录。最好创建一个名为 public 的目录,将其中的 cssjs 目录移动到该目录中。

之后,您的 CSS 文件的 URL 将是 /css/xxxx.css,而您的 JS 文件的 URL 将是 /js/xxxx.js

请告诉我们 ^^

英文:

The directory that you declare as static with app.use(express.static(staticPath)); shouldn't be the js directory. You'd better create a directory like public in which you move your css and js directories.

After that, your url for your css files will be /css/xxxx.css and for your js files /js/xxxx.js

Let us know ^^

huangapple
  • 本文由 发表于 2023年7月10日 22:06:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76654560.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定