gpt4 book ai didi

node.js - Node.js 中的应用程序结构?

转载 作者:太空宇宙 更新时间:2023-11-04 02:59:51 25 4
gpt4 key购买 nike

我熟悉 Java Web 容器,其中 Web 应用程序部署为 war 文件。

我很困惑如何在 Node.js 中部署 CSS、JS、HTML、图像(等等)。如何做到这一点?

我对 Node.js 的了解非常有限。提前致谢!

最佳答案

http://expressjs.com/

http://expressjs.com/guide.html#configuration

app.js

app.configure(function(){
var oneYear = 31557600000;
app.use(express.static(__dirname + '/public', { maxAge: oneYear }));
app.use(express.errorHandler());
});

app.listen(8888);

index.html

<html>
<head>
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<span class='hello'>Hello world!</span>
</body>
</html>

索引.css

.hello { color: green; }

目录结构:

project/
app.js
public/
index.html
css/
index.css

运行您的应用程序:node app.js

访问您的网站:http://localhost:8888

目录和文件名是任意的。一切都是可配置的,没有什么是复杂的。一般来说,没有人试图让您与 Node 中的特定目录结构或命名方案绑定(bind)。

去捕获他们,老虎。

关于node.js - Node.js 中的应用程序结构?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7046628/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com