简体   繁体   中英

Architectural approach to complex system in NodeJS

We're building a complex system in NodeJS that will have a number of segments that are managed by separate teams, each of which represents a single feature of the system. Therefore, there will be one "master app" that includes each of these segments, or "modules", into a Web-based UI (using Express server, as of this writing).

Each segment may have one or more NodeJS module, and each team only has the authority to make changes to their respective segments, so there can be no unilateral cross-team interference, and each segment can be versioned, tested and released independently of other modules.

NodeJS is new to us, and we're struggling to understand how such an approach can be architected, as it seems like when you do a require() call to include a package, there is an underlying assumption that there is a single module. So, one of our fundamental questions is, how can you include a single package that allows for making require() calls for multiple modules from that package? Also, how to manage and version each segment/package, independently?

Also, from a Web server perspective, how are resources from the various packages (like CSS, images, etc.) combined to be accessible from the browser?

We're looking for suggestions, resources, knowledge - possibly even someone to come on-site to consult with us about architecting the development and deployment environments - to help kick-start us in the right direction. Any input is appreciated. :)

  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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM