简体   繁体   English

如何将Angular js添加到现有的node.js应用程序?

[英]how to add angular js to an existing node.js application?

I am working my way through building my first node.js app, with a mongodb backend. 我正在通过mongodb后端构建我的第一个node.js应用程序。 I didn't install any frameworks (like mean.io) but am just trying to build step by step so I understand what each component does etc. 我没有安装任何框架(例如mean.io),但只是尝试逐步构建,因此我了解每个组件的作用等等。

So far, so good. 到现在为止还挺好。 My node js app exposes a GET method via express, and queries my mongdb. 我的节点js应用程序通过express公开了GET方法,并查询了我的mongdb。 Right now it just dumps out a bunch of json data. 现在,它只是转储一堆json数据。

Now, I'd like to start working on the GUI. 现在,我想开始使用GUI。 So I've been looking at angularjs. 所以我一直在看angularjs。 I've installed it using this command: 我已经使用以下命令安装了它:

me@mydevbox:/var/www/html/node/inventory$ sudo npm install angularjs
inventory@0.0.0 /var/www/html/node/inventory
└── angularjs@0.0.1 

When i check npm for an inventory of what's been installed, this is what I see: (this is just a partial list... to keep my question / post short and readable) 当我检查npm的安装清单时,这就是我看到的内容:(这只是部分清单,以使我的问题/帖子简短易懂)

me@mydevbox:/var/www/html/node/inventory$ npm ls
inventory@0.0.0 /var/www/html/node/inventory
├── angularjs@0.0.1 extraneous
├─┬ mongodb@2.2.5
│ ├── es6-promise@3.0.2
│ ├─┬ mongodb-core@2.0.7
│ │ ├── bson@0.5.2
│ │ └─┬ require_optional@1.0.0
│ │   ├── resolve-from@2.0.0
│ │   └── semver@5.3.0
│ └─┬ readable-stream@1.0.31
│   ├── core-util-is@1.0.2
│   ├── isarray@0.0.1
│   └── string_decoder@0.10.31
├─┬ mongoose@4.5.8
│ ├── async@1.5.2
│ ├── bson@0.4.23
│ ├── hooks-fixed@1.2.0
│ ├── kareem@1.1.3
│ ├─┬ mongodb@2.1.18
│ │ └── mongodb-core@1.3.18
│ ├── mpath@0.2.1
│ ├── mpromise@0.5.5
│ ├─┬ mquery@1.11.0
│ │ ├── bluebird@2.10.2
│ │ ├── debug@2.2.0
│ │ └── sliced@0.0.5
│ ├── muri@1.1.0
│ ├── regexp-clone@0.0.1
│ └── sliced@1.0.1
├─┬ morgan@1.6.1
│ ├── basic-auth@1.0.4
│ └── on-headers@1.0.1
└── serve-favicon@2.3.0

npm ERR! extraneous: angularjs@0.0.1 /var/www/html/node/inventory/node_modules/angularjs

In reading other posts, some seemed to suggest it has to do with the user (eg. not using root) you install the package with. 在阅读其他文章时,似乎有人暗示这与安装软件包的用户有关(例如,不使用root用户)。 But that doesn't seem to be the problem here. 但这似乎不是这里的问题。

Questions 问题

I'd like some help diagnosing this error that I'm seeing... Also once I have it installed properly, what's the best way to integrate angular into my existing node js application? 我希望获得一些诊断此错误的帮助...同样,一旦正确安装它,将angular集成到现有节点js应用程序中的最佳方法是什么? The examples I've seen online talk about how to initialize a new app but that's not what I'm looking for. 我在网上看到的示例都在谈论如何初始化新应用,但这不是我想要的。

Thanks! 谢谢!

npm ERR! npm ERR! extraneous means you didn't save the module in your package.json 无关紧要意味着您没有将模块保存在package.json中

Install again using --save 使用--save重新安装

npm install angular --save

(Also you installed angularjs instead of angular, I don't know the difference, but I would check it out) (还安装了angularjs而不是angularjs,我不知道区别,但是我会检查一下)

The integration between the backend and the front in angular is made with services and the $http angular object. 后端和前端在angular中的集成是通过服务和$ http angular对象进行的。

I recommend you to do some angular tutorials, google has lots of them. 我建议您做一些角度教程,谷歌有很多

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

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