Node.js + Angular = Uncaught ReferenceError: require is not defined

angularjs, express, node.js

Solution

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, 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 makes an $http call to Node.js which requires and talks to the mongodb.

Problem

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. 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-express-bootstrap-seed/ 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] ``` How can I use node modules in Angular.js files?

Original source