【问题标题】:the application structure in node.js?node.js 中的应用程序结构?
【发布时间】:2011-08-12 21:42:26
【问题描述】:

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

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

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

【问题讨论】:

  • 尝试使用express
  • 看看这个例子来创建一个节点服务器来提供静态文件:gist.github.com/701407
  • 谢谢大家。虽然我不是很清楚,因为我用过 .war 。我假设文件夹结构是 xxx.js 格式
  • @Preethi 我在自己的博客中使用this structure
  • 谢谢 Raynos,我明白了。关于 node.js 可用的各种框架的任何想法?我需要与 SQL db 交谈,但我不确定现有的 node.js 是否支持。 Jorgen 提到过看起来很有趣的“expresso”

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


【解决方案1】:

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>

index.css

.hello { color: green; }

目录结构:

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

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

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

目录和文件名是任意的。一切都是可配置的,没有什么是复杂的。一般而言,没有人试图让您与特定的目录结构或节点中的命名方案联系在一起。

去抓他们,老虎。

【讨论】:

    猜你喜欢
    • 2018-02-02
    • 1970-01-01
    • 2018-08-30
    • 1970-01-01
    • 2016-09-06
    • 2012-12-09
    • 2014-10-16
    • 2017-06-09
    • 1970-01-01
    相关资源
    最近更新 更多