Node.js的角度+ =未捕获的Ref​​erenceError:要求没有定义角度、定义、js、Node

2023-09-13 04:52:33 作者:成绩总挑拨我和手机的关系

我创建的Node.js服务器上的防爆press.js API。该API用于访问存储在服务器上的数据。我还留着一个日志谁的访问API在数据库中。

I'm creating an Express.js API on a Node.js server. The API is used to access data stored on the server. I also keep a log of who's accessing the API in a database.

我试图创建使用Angular.js整齐地显示管理员访问日志管理员部分。我用角前preSS引导种子开始我的项目:

I'm trying to create an admin section that will use Angular.js to display the admin access logs neatly. I used the Angular Express Bootstrap seed to start my project:

https://github.com/jimakker/angular-ex preSS-引导种子/

我的问题是我需要的controllers.js访问节点模块,但它似乎不知道节点存在。这是我的错误:

My problem is that I need the controllers.js to access node modules but it doesn't seem to know that node exists. Here is my error:

controller.js

var mongo = require('mongodb');
[Uncaught ReferenceError: require is not defined]

我如何使用节点模块Angular.js文件?

How can I use node modules in Angular.js files?

推荐答案

节点是一个服务器端的技术,你通常不会使用与Angular.js浏览器您的节点模块。但是,如果你想CommonJS的需要在浏览器中看到的功能:https://github.com/substack/node-browserify.

Node is a server side technology, you would not typically use your node modules on the browser with Angular.js. However, if you want commonjs require functionality in the browser see: https://github.com/substack/node-browserify.

Ofcourse,浏览器无法说话直接的MongoDB这就是为什么你首先需要一个API,角将使用HTTP您的API进行通信。

Ofcourse, a browser can't talk to mongodb directly which is why you need an API in the first place, angular would communicate with your API using HTTP.

Angular.js使一个HTTP $调用Node.js的要求和谈判MongoDB的。

Angular.js makes an $http call to Node.js which requires and talks to the mongodb.