【问题标题】:node.js module or require.jsnode.js 模块或 require.js
【发布时间】:2013-09-18 07:14:43
【问题描述】:

我想编写 web 应用程序并使用 express.js 作为 web 框架。作为测试框架,我将使用 mocha 和 chai。

Node.js 支持模块化编程,我可以像 require("mocha") 一样加载模块。在前端我使用 require.js 在模块中组织我的代码,但这可以在 node.js 中使用。最好在 node.js 中使用 require.js 或使用 node.js 标准模块。

我知道 require.js 支持 AMD 并使用 mocha 测试代码可能会很复杂,因为代码将异步加载。

模块加载需要 Node.js 还是 require.js?

【问题讨论】:

    标签: node.js requirejs


    【解决方案1】:

    支持CommonJS 模块格式。

    如果您有想要在浏览器和 node.js 中使用的模块,您可以use require.js in node

    【讨论】:

    • 但是 commonjs 和 requirejs 哪个更好?
    • 这取决于你想做什么。 require.js 使用函数包装方法(如 here 所述)异步加载模块。 IMO 它的设计考虑了浏览器。 node.js 中不需要它,除非你要为浏览器和 node 编写一个模块。
    猜你喜欢
    • 2013-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-19
    • 1970-01-01
    • 1970-01-01
    • 2012-06-19
    • 2012-07-30
    相关资源
    最近更新 更多