加载时 index.js 会降低 Nodejs 的速度吗

Does index.js slowdown Nodejs when loading

我的 NodeJS 应用程序需要很长时间(30 秒)来加载和重新加载 nodemon 的每次更改。我有 15 个实用程序和 35 条路线。我有一个 utils/index.js 和 routes/index.js 文件,可以导入和导出相应文件夹中的所有内容。

我怀疑 index.js 文件可能导致应用程序同时加载 import/export 所有文件,这可能会在启动时以某种方式减慢它的速度。

问题:index.js 会减慢 NodeJS 的速度吗?我加载路线的方式效率低下吗?或者启动这种大小的应用程序 30 秒是否正常?

routes/route1.js

export const route1 = (app) => {
  app.get('/route1', (req, res, next) => { ... }
}

routes/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);

不要将每个路由都放在一个文件中,而是将它们放入文件中的一个类别,这样加载时间就会减少并使用 https://expressjs.com/en/guide/routing.html#express-router 不要导出函数,只需导出路由器对象,这样你就不必执行函数