Getting started with Node.js, angular.js and MongoDB, modeling relations and other ramp up tips [closed] Getting started with Node.js, angular.js and MongoDB, modeling relations and other ramp up tips [closed] mongodb mongodb

Getting started with Node.js, angular.js and MongoDB, modeling relations and other ramp up tips [closed]


Doing apps where you have both a server-side component, as-well as a client-side component makes things a little more complicated then just having a server-side framework.

  • When using a client-side framework like AngularJS, all your templates are compiled client-side, not server-side. That's a huge difference from traditional server-side rendering. That means, instead of sending rendered HTML to the client, you would send JSON. Your server would essentially become a RESTful API with security emplacements.

  • I'm not extremely familiar with AngularJS, more with Ember, but you would essentially create a restful service: https://gist.github.com/2432692 . That would communicate with the server on a RESTful interface.

  • On the server, using nodejs, you would use an ORM like Mongoose or something similar. You can create relationships, documents, etc... One note, you'll have to duplicate your models on both, the server and client.

  • MongoDB uses bson, a binary encoding of a serialized JSON string/object. Because nodejs is built using V8 JavaScript engine, JSON is a natural object type and so working with MongoDB is extremely simple.

  • HTTP Server on NodeJS: NodeJS provides a base implementation for an http server. It's not much, but you can respond to and handle requests. There are no session, cookie, auth support, so you can either use connect which builds on-top of the traditional http server or use ExpressJS which builds on both connect and the normal http server that node provides. ExpressJS is extremely easy to get started on, and works well with RESTful backends.

It's pretty simple. Get ExpressJS, create a new app, setup all the client-side stuff (angularJS) and module systems if you use AMD, CommonJS, Browserify, etc...


I am not familiar with node.js, but for mongodb design, you'll have to choose between "subdocuments" vs "linking documents".

1

You can have a look at how to structure many-to-many relationships in mongoose?.

Idea is to retrieve a complete document where it makes sense. For instance, you might have the following schema.

{ customer : { name: xxx },  appointments: [ {date: xx, type : xxx .., servicerep: xxx}, {date: xx, type : xxx .., servicerep: xxx} ]}

even though, info may be duplicated, for queries, you only hit one document/subdocument.

4

Even though it might be client side, it does not mean server should not validate. Client could validate as best as it can, but server still ought to verify. Sorry, I don't have anymore to add.