最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Node.js app结构,“按功能分类”路由

运维笔记admin30浏览0评论

Node.js app结构,“按功能分类”路由

Node.js app结构,“按功能分类”路由

我正在制作一个可扩展的REST-API,但我几乎找不到关于高级应用程序的高级node.js应用程序结构的文章,因为大多数都使用简单的入门项目。

我正在使用“逐个功能”结构,基于这个article和这个answer。

我的问题:以下解决方案的更好结构是什么?

1.将路线保存在单独的文件夹中:

src
  product
    index.js
    product.spec.js
  routes
    index.js
    product.js
    user.js
  user
    index.js
    user.spec.js

2.将路径放入相应的文件夹:

src
  product
    index.js
    product.route.js
    product.spec.js
  user
    index.js
    user.route.js
    user.spec.js

使用index.js文件中的路由。

还有更好的解决方案吗?

任何有关高级,可扩展节点项目结构的文章都将受到赞赏!

回答如下:

由于这是一个意见问题,这是我的:

我的构建迁移了从srcdist的所有东西。有些是编译的,有些是刚刚复制的。然后我直接从dist文件夹运行。

src
  api
    <api files/folders>
  lib
    <common lib files/folders>
  routes
    <Route files (app.use, app.get, etc.)>
  static
    <static css, images, script, etc.>
    <I do not include src code that is compiled in any way>
  ui
    <LESS, SASS, JS, etc that will be compiled, combined, packed, etc>
  views
    <ejs files>
  app.js

src/ui/**的事情被编译并放入dist/static/**

发布评论

评论列表(0)

  1. 暂无评论