简体   繁体   English

无法为HTML / Node.js服务器加载CSS文件

[英]CSS File not loading for HTML/Node.js server

I am making a url shortener called "Shrimp".我正在制作一个称为“虾”的网址缩短器。 Currently, here is my Node.JS:当前,这是我的Node.JS:

 const express = require('express'); const app = express(); app.get('/', (req, res) => { res.sendFile(__dirname + '/index.html') }); app.listen(3000, () => { console.log('server started'); });

And my HTML:而我的HTML:

 <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="/style.css"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Shrimp</title> </head> <body> <h1>Shrimp</h1> <p>URL Shortener</p> <br> <form action=""> <input type="text" id="url" placeholder="URL to shorten" required> <input type="text" id="key" placeholder="Key (Optional)"> <button type="submit">Submit</button> </form> </body> </html>

Pretty simple, but the CSS is not loading!很简单,但是CSS没有加载! Can anybody help?有人可以帮忙吗?

I am making a url shortener called "Shrimp".我正在制作一个称为“虾”的网址缩短器。 Currently, here is my Node.JS:当前,这是我的Node.JS:

 const express = require('express'); const app = express(); app.get('/', (req, res) => { res.sendFile(__dirname + '/index.html') }); app.listen(3000, () => { console.log('server started'); });

And my HTML:而我的HTML:

 <!DOCTYPE html> <html lang="en"> <head> <link rel="stylesheet" href="/style.css"> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Shrimp</title> </head> <body> <h1>Shrimp</h1> <p>URL Shortener</p> <br> <form action=""> <input type="text" id="url" placeholder="URL to shorten" required> <input type="text" id="key" placeholder="Key (Optional)"> <button type="submit">Submit</button> </form> </body> </html>

Pretty simple, but the CSS is not loading!很简单,但是CSS没有加载! Can anybody help?有人可以帮忙吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM