Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I am coming from Java and relational world and trying to get my feet wet. The app i am working on is an appointment scheduling system using node.js and MOngo on backend and client is in angular.js.

I am trying to understand couple of key concepts which might be remnants of my Java bias. any help in pointing to relevant snippets, tutorials is appreciated.

1) How would i manage relationships between appointment, customer and service representative in Mongo/Node? Do the appointment objects get created and a reference of user id stored in appointment? Does user need to have a reference to list of appointments?

2) User authn/authz, since node is being used as restful service provider how do i create role based control? For example when a user signs up as a service rep he should be approved. Is there a module which can help?

3) Any generic module which gives reports on user signups etc?

4) How do people manage permissions on client side MVC?

Any pointers are greatly appreciated.

like image 854
retrobrain Avatar asked Dec 05 '12 00:12

retrobrain


People also ask

How do angular and node work together?

NodeJS takes part in loading the AngularJS application with all the dependencies, such as CSS files and JS files in the browser. For loading all the assets of Angular and accepting all the API calls from the AngularJS applications, NodeJS is generally used as a web server.


2 Answers

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...

like image 87
Daniel Avatar answered Sep 21 '22 23:09

Daniel


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.

like image 34
Nasir Avatar answered Sep 19 '22 23:09

Nasir