【问题标题】:Easy way to prepare the environment for ES6 "import x" instead of "require(x)" in the express为 ES6 "import x" 而不是 express 中的 "require(x)" 准备环境的简单方法
【发布时间】:2022-01-07 05:22:08
【问题描述】:

我需要一种简单的方法来为 import x 而不是 express 项目中的 require(x) 准备环境。

我只找到了可以手动执行的方法,但我认为这不是最好的方法。

有没有为此准备环境的 npm 包或 GitHub 模板?

【问题讨论】:

    标签: node.js express ecmascript-6 import require


    【解决方案1】:

    您可以使用 .mjs 文件代替 .js 文件。 文档可以在here找到。

    或者指定你想使用模块作为documentation shows

    但对于可扩展的应用程序,您应该使用结构良好的代码。 例如使用NestJS,它是用开箱即用的 express 构建的。 (它需要一个最低限度的 Typescript 理解)

    【讨论】:

      猜你喜欢
      • 2019-03-03
      • 2018-03-22
      • 2019-08-31
      • 2015-10-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      • 2021-11-01
      相关资源
      最近更新 更多