按组件构造node.js项目

问题描述 投票:1回答:1

我正在按照此Node.js最佳实践repo,按组件构建Node.js项目。

所以我的问题是,我该如何放置Order并更新db中剩余的Product项目。我应该在ProductsService组件内使用Order

有人已经实施这种方法了吗?你能举个例子吗?谢谢!

node.js architecture structure
1个回答
0
投票

如果ProductsService包含导出的方法或函数,则应在Order组件内部使用此导出的函数来更新数据库中的产品。

示例

mymodule.js

// exported function
const myFunction = function(foo) {
  if(foo) {
    return bar;
  }
}

module.exports = myFunction;

index.js

const myModule = require('./mymodule.js');
// using the function
myModule(value);
© www.soinside.com 2019 - 2024. All rights reserved.