【问题标题】:Node.js Express using require vs app.getNode.js Express 使用 require 与 app.get
【发布时间】:2013-03-04 14:23:20
【问题描述】:
# app.get "/example", example.index

# require("./routes/index") app

我知道我的第一行代码转到名为 example 的控制器并使用 index 函数。 我不太确定第二行是做什么的。这个比那个好吗?完整的解释将不胜感激。

【问题讨论】:

    标签: node.js express coffeescript


    【解决方案1】:

    第一行:app.get "/example", example.index 表示如果有人点击了 URL http://localhost:3000/example,那么你正在加载 example 文件(大概是上面的某处 required)并在其上运行 index 函数。

    第二行require("./routes/index") app 只是requireroutes 文件夹中输入一个名为index.coffee 的文件,并将app 作为变量传递。

    【讨论】:

    • localhost:3000 几乎是节点应用程序的默认主机:端口。 /example 是因为您指定了 app.get '/example'
    猜你喜欢
    • 1970-01-01
    • 2014-05-08
    • 1970-01-01
    • 1970-01-01
    • 2012-02-15
    • 1970-01-01
    • 2013-09-29
    • 2023-02-19
    • 2018-08-04
    相关资源
    最近更新 更多