【发布时间】:2021-08-08 02:44:27
【问题描述】:
我的 NodeJS 应用程序需要很长时间(30 秒)来加载和重新加载使用 nodemon 进行的每次更改。我有 15 个实用程序和 35 条路线。我有一个 utils/index.js 和 routes/index.js 文件,用于导入和导出这些文件夹中的所有内容。
我怀疑 index.js 文件可能会导致应用一次加载和导入/导出所有文件,这可能会在启动时以某种方式减慢它。
问题:拥有 index.js 会减慢 NodeJS 的速度吗?我加载路线的方式效率低吗?或者启动这种大小的应用需要 30 秒正常吗?
routes/route1.js
export const route1 = (app) => {
app.get('/route1', (req, res, next) => { ... }
}
路由/index.js
// I'm using latest ES6 imports
import { route1 } from './route1';
// ...
import { route35 } from './route35';
export const route = (app) => {
route1(app);
// ...
route35(app);
}
App.js
// ...
import { routes } from 'routes/index';
routes(app);
【问题讨论】:
标签: node.js performance import routes