yeoman mongodb - require is not defined

I'm trying to connect a yeoman generated app to mongodb.

I've added following line to my app.js file :

var mongodb = require('mongodb');

Run the test server using the command :

grunt server

...and I got error require is not defined.

What's wrong ? Thks,

You are confusing backend with frontend code. Yeoman is for scaffolding out your frontend application. This could be Backbone, Ember.js or AngularJS. Those live in the user's browser, so naturally they have no direct access to any resources on your server, which includes MongoDB.

What you want is a separate backend that exposes an API that your frontend application can talk to, for example through a simple RESTful API. You should check out the Mean stack to learn more about this which is Mongo, Express, Angular + Node.

Like passy said, you need to have a backend - right now all you have is the frontend (angular).

passy gives a great answer, but I just want to add that I personally use both the yo generator and an express generator, do a bit of fine tuning, and eventually have a full MEAN stack. That might be what works for you.