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

标签 node.js web-applications code-structure application-structure

我熟悉 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/

相关文章:

javascript 未在 HTML 文件中加载 - NodeJS + ExpressJS

google-app-engine - 如何使用 webapp.RequestHandler 链处理请求

c++ - 在 C++ 中显式声明默认方法

python - 干净地处理多个变量的类型错误

Javascript 对象性能偏好

node.js - 错误: ENOENT: no such file or directory NodeJS

javascript - 在 Node.js 中记录每个函数调用,而不进行无限递归

javascript - 动态添加文件以请求发布

security - 强制字母数字用户 ID

android - Android 上的离线 Web 应用程序 HTML5