【发布时间】:2021-04-07 04:19:16
【问题描述】:
我决定在 NodeJS/Express 项目中使用新的 ES6 导出而不是使用模块导出。我正在阅读 MDN 文档,它说导出是这样使用的:
export function draw(ctx, length, x, y, color) {
ctx.fillStyle = color;
ctx.fillRect(x, y, length, length);
在这里,我尝试在此 app.get 函数中以相同的方式使用它,但我的编辑器抛出语法错误。我应该使用其他格式吗? - 我实际上是在尝试将路由容器分成单独的文件以进行组织 - 然后最后将它们导入我的主 app.js 文件以使用 express 进行路由声明。
export app.post('/exampleroute', async (req, res) => {
...
});
// Error: Declaration or Statement expected.
【问题讨论】:
-
你想在那里导出什么样的绑定?您想如何导入和使用该路线?
app是什么(即它来自哪里)?
标签: javascript node.js express ecmascript-6 es6-modules