首页 > 解决方案 > How to Integrate angular cli project with nodejs/expressjs project

问题描述

I have 2 projects, as shown in the following images. The Node, and Express project is in the root folder, and the Angular CLI project inside of angular-src folder. I can run each project individually, back-end on port 3000 with node app.js and front-end on port 4200 with ng serve What is the best way to integrate both projects, and the easiest in deployment?

Full Project Folder Full Project Folder with angular src files shown

标签: node.jsmongodbexpressangular-climean-stack

解决方案


大多数人将他们的前端 (fe) 和后端 (be) 保存在单独的存储库中。当你认为你可以有多个 fe 时,这是有道理的。

但是,将它们保存在同一个存储库中通常更容易。然后,当您部署时,您只需要克隆一个 repo。

另外,这取决于你走哪条路线。你会在你的服务器上安装 Node.js 等,还是沿着 docker 路线走?

人们经常喜欢使用 docker 来容器化他们的 fe 和 be。这种方法的好处是您只需要在您部署的每台服务器上安装一个依赖项,即 docker 本身。其他一切都存在于 docker 世界中。

此外,docker 可以轻松地从任何服务器进行 docker pull。如果出现问题,只需杀死您的 docker 容器并启动一个新容器(假设您的数据不会因此而丢失,这不是 fe 的担心,而是一个值得关注的问题)。

显然,有 docker 学习曲线,但并不太痛苦。


推荐阅读