简体   繁体   English

Angular 项目结构,带有单独的 package.json 文件

[英]Angular Project Structure with separate package.json files

I saw this Project Structure in Angular with Node.js as backend, where the Angular node modules and package.json were in the "app" folder, while the node.js' node modules and package.json were in the root of the project. I saw this Project Structure in Angular with Node.js as backend, where the Angular node modules and package.json were in the "app" folder, while the node.js' node modules and package.json were in the root of the project. (watch picture) (看图片)

在此处输入图像描述

How do i get the requested outcome?我如何获得要求的结果?

  • Create the root directory.创建根目录。
  • From within the directory, run 'npm init'在目录中,运行“npm init”
  • To create the server file, run 'touch server.js'要创建服务器文件,请运行“touch server.js”
  • Then, to create the angular app, from inside the root directory, run 'ng new app-name'然后,要创建 angular 应用程序,从根目录中运行“ng new app-name”

Step 1:- Run npm i @angular/cli@latest in command prompt第 1 步:- 在命令提示符下运行npm i @angular/cli@latest

Step 2:- create a empty folder.第 2 步:- 创建一个空文件夹。

Step 3:- go to your newly created folder inside command prompt.第 3 步:- go 到命令提示符内新创建的文件夹。

Step 4:- run npm init第 4 步:- 运行npm 初始化

Step 5:- then run ng new my-app第 5 步:- 然后运行ng new my-app

Step 6:- then run touch server.js第 6 步:- 然后运行touch server.js

I recommand that you use NX https://nx.dev/ , it will give you a perfect structure and many benefits of monorepos, you can have multiple angular apps and a node backend taht you can it as an app like this我建议您使用 NX https://nx.dev/ ,它将为您提供完美的结构和 monorepos 的许多好处,您可以拥有多个 angular 应用程序和一个节点后端,您可以将其作为这样的应用程序

ng g node-app backend-api

You will have a structure like this:您将拥有这样的结构:

apps/
  angularApp-1/
  angularApp-1-e2e/
  angularApp-2/
  angularApp-2-e2e/
  api/ //your node app
   src/
     app/
     assets/
     environemnts/
     main.ts
   jest.config.js
   tsconfig.app.json
   tsconfig.spec.json
  tslint.json 
libs/

tools/
angular.json
nx.json
package.json
tsconfig.json
tslint.json

The node_modules folders should be seperated between the Angular front end and the Node backend. node_modules 文件夹应该在 Angular 前端和 Node 后端之间分开。 Eg A standard project structure for a full stack angaulr/node app should be something like.例如,全栈angaulr/node 应用程序的标准项目结构应该类似于。

.
├── ProjectName
|   ├── angular-app-name
|   └── server

For a Project structure like this run对于像这样运行的项目结构

  • mkdir ProjectName //Create project root directory mkdir ProjectName //创建项目根目录
  • mkdir server //Create node server folder mkdir server //创建节点服务器文件夹
  • cd server光盘服务器
  • npm init //Initialize npm npm init //初始化npm
  • touch server.js //Create server js file for node backenk touch server.js //为节点后端创建服务器js文件
  • cd.. //Back to Project root cd.. //回到项目根目录
  • ng new {app-name} //Create angular project ng new {app-name} //创建angular项目

From what I can tell you want something like this, with your angular app sitting within the node backend.据我所知,你想要这样的东西,你的 angular 应用程序位于节点后端。

.
├── ProjectName
|   ├── angular-app-name
|   └── server.js
|   └── node_modules
  • mkdir ProjectName //Create project root directory mkdir ProjectName //创建项目根目录
  • npm init //Initialize npm npm init //初始化npm
  • touch server.js //Create server js file for node backenk touch server.js //为节点后端创建服务器js文件
  • ng new {app-name} //Create angular project ng new {app-name} //创建angular项目

I personally think the more standard project-> backend/frontend structure makes more sense, but both will work fine.我个人认为更标准的项目-> 后端/前端结构更有意义,但两者都可以正常工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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