NodeJS 中復雜系統的架構方法 (Architectural approach to complex system in NodeJS)


問題描述

NodeJS 中復雜系統的架構方法 (Architectural approach to complex system in NodeJS)

我們正在 NodeJS 中構建一個複雜的系統,其中包含多個由不同團隊管理的部分,每個部分代表系統的一個單一功能。因此,將有一個“主應用程序”將這些段或“模塊”中的每一個包含到基於 Web 的 UI 中(在撰寫本文時使用 Express 服務器)。

每個段可能有一個或多個 NodeJS 模塊,每個團隊只有對各自的 Segment 進行更改的權限,因此不會有單方面的跨團隊干擾,並且每個 Segment 都可以獨立於其他模塊進行版本控制、測試和發布。

NodeJS 對我們來說是新的,我們正在努力理解如何構建這種方法,就像當你調用 require() 來包含一個包時一樣,有一個基本假設,即只有一個模塊。因此,我們的一個基本問題是,如何包含一個允許從該包中對多個模塊進行 require() 調用的包?此外,如何獨立地管理和版本化每個段/包?

此外,從 Web 服務器的角度來看,如何將來自各種包(如 CSS、圖像等)的資源組合起來以便從瀏覽器?

我們正在尋找建議、資源和知識——甚至可能有人來現場與我們就開發和部署環境的架構進行諮詢——以幫助我們正確地啟動方向。任何輸入表示讚賞。:)

如何包含一個允許從該包中對多個模塊進行 require() 調用的包?此外,如何獨立管理和版本化每個段/包?

此外,從 Web 服務器的角度來看,如何將來自各種包(如 CSS、圖像等)的資源組合起來以便從瀏覽器?

我們正在尋找建議、資源和知識——甚至可能有人來現場與我們就開發和部署環境的架構進行諮詢——以幫助我們正確地啟動方向。任何輸入表示讚賞。:)

如何包含一個允許從該包中對多個模塊進行 require() 調用的包?此外,如何獨立地管理和版本化每個段/包?

此外,從 Web 服務器的角度來看,如何將來自各種包(如 CSS、圖像等)的資源組合起來以便從瀏覽器?

我們正在尋找建議、資源和知識——甚至可能有人來現場與我們就開發和部署環境的架構進行諮詢——以幫助我們正確地啟動方向。任何輸入表示讚賞。:)

從 Web 服務器的角度來看,如何將來自各種包(如 CSS、圖像等)的資源組合起來以便從瀏覽器訪問?

我們正在尋找建議、資源、知識——甚至可能有人到現場與我們就開發和部署環境的架構進行諮詢 ‑ 幫助我們朝著正確的方向前進。任何輸入表示讚賞。:)

從 Web 服務器的角度來看,如何將來自各種包(如 CSS、圖像等)的資源組合起來以便從瀏覽器訪問?

我們正在尋找建議、資源、知識——甚至可能有人來現場與我們就開發和部署環境的架構進行諮詢 ‑ 幫助我們朝著正確的方向邁進。任何輸入表示讚賞。:)


參考解法

方法 1:

  1. Since your team is new to node.js, the first thing to do is to understand the awesome package manager of node.js, https://www.npmjs.com . If you can understand how they manage the package/module in node.js, then you will get the basic concept to manage the modules among your team.
  2. Using package.json is a good start to understand how to manage and share each independent module. Using npm with package.json can help you to handle the versions of module and submodule required by your application.
  3. Git is your good friend.
  4. You may want to try npm Enterprise which is a solution to your case. I didn't mean to ask you to use their service, but it would be good to your team if you know how it works.
  5. static assets(css, images, etc) should be in a separate repository and shared among all the modules which require those assets.

  6. </ol>

    It's not easy to master in your case but the module model of Node.js + npm should definitely be good to your team.

    方法 2:

    The best example you can study is the Express middlewares, such as body‑parser. They used to be all in the Express module.

    You would call in Express 3.x like this:

    const express = require('express');
    
    const app = express();
    app.use(express.bodyParser())
    

    After Express 4.x you have to call like this:

    const express = require('express');
    const bodyParser = require('body‑parser');
    
    app.use(bodyParser())
    

    From the Migrating to Express 4 guide:

    This means that Express is now an independent routing and middleware web framework, and Express versioning and releases are not affected by middleware updates.

    Without built‑in middleware, you must explicitly add all the middleware that is required to run your app.

    So, do not go for calling a single module and accessing all its children, but create individual modules, that will be required separately. This is the common pattern in big NodeJS modules today.

    (by user1588877iKoalaLuís Brito)

    參考文件

    1. Architectural approach to complex system in NodeJS (CC BY‑SA 2.5/3.0/4.0)

#projects #architecture #module #packages #node.js






相關問題

Netbeans 運行我所有的項目 (Netbeans runs all my projects)

Cara berbagi konfigurasi antara Dua atau lebih lingkungan TRAC (How To share configurations between Two or more TRAC environments)

Visual Studio 2005安裝程序項目安裝在終端服務器上崩潰 (Visual Studio 2005 Setup project install crashes over Terminal Server)

XCode 項目詳情? (XCode Project Details?)

Visual Studio 2005項目選項 (Visual Studio 2005 Project options)

布朗菲爾德VS格林菲爾德的發展? (Brownfield vs Greenfield development?)

NodeJS 中復雜系統的架構方法 (Architectural approach to complex system in NodeJS)

使用Wiki作為中央開發項目存儲庫 (Using a wiki as a central development project repository)

開發 Web 服務器的技巧 (Tips for developing a web server)

Visual Studio 解決方案/項目組織 (Visual Studio solution/projects organization)

為什麼我的項目在沒有變化的情況下構建? (Why do my projects build when there are no changes?)

如何使用開源項目改進我的 C++ (How to improve my C++ with open source projects)







留言討論