pj-ita
Last Updated: February 25, 2016
·
5.586K
· alchemycs
Profile pic

3 Tips To Building Enterprise Grade Angular/Node Applications

I've just finished building the pilot application for 'Policy Connect' which is a web based application for delivering legislative policies to industry organisations such as 'Housing'.

This isn't a funky social media style thing with social graphs and predictive suggestions on what style of underwear you might enjoy based on your followers - it's a business tool with legislative and training content that is designed to keep employees out of hospital and employers out jail!

Picture

But guess what: it's built on AngularJS, Node and CouchDB all running on Heroku and Cloudant!

So here are a few tips...

1. Do Your Controllers Correctly

Almost every fiddle or example I've seen defines controllers as a global function. Don't do this as not only does it pollute your window global but it makes minification problematic. You should be using something like:


angular.module('myApp', ['dependancies']) .controller('Controller1', ['$scope', ..., function($scope, ...) { //Controller code }); </code> </pre> 2. Script Loaders Are Your Friend You can easily use angular's module and dependancy system to isolate your modules into manageable parts. Enhancing this by using script loaders such as Require JS allows you to easily keep track and manage the file dependancies of your modules and you can easily minify your application into a single javascript file when you are ready to deploy. 3. Make Your Code DRY by Modulerising Shared Code If you use Require JS you can easily make sharable modular code by using something like Universal Module Definition patterns. You might also want to look at Browserify. I haven't looked at it in any detail, but my impression is that it doesn't give me that fine grained control to keep my front end lean. One of the major things touted about having a NodeJS server is that your front and back end is written in Javascript. This means you shouldn't need to write two sets of code for validating complex objects. In my case I'm using flatiron/resourceful for server side modeling. I've seperated out the schema definition into a sharable module so I can then use flatiron/revalidator on both the front and backend to validate my data and have only one definition of the schema shared by both. Summary These are probably the top 3 things that can be easily shared in a pro-tip! I would like to write some more and make a tutorial - living behind the corporate wall working on private web applications makes it hard to share things (show off ;) directly. If you would think an in depth tutorial on building an enterprise grade application is worth while, I find up votes to be inspiring. P.S. Other things you should do include: Profiling - still trying to find some good tools to do this with node/angular Unit tests End to end tests EXPECTATION MANAGEMENT! Now you can make exciting interactive web based apps faster, don't let management force you into technical debt
Say Thanks
Respond

2 Responses
Add your response

12974
1bb7923ee4db71c6af51c944d787d5b2

Hey great write up. One thing I struggle with is good Security patterns. With angular your app is running on the client. So the user can view source and then see what the rest service end points are. At that point they can start to try and hack the service. Any pointers and tips on securing an enterprise application?

over 1 year ago ·
14045
D42a7264714dee5006b9c99d2567a320

@jyanes83 There's a simple answer here: the security of your application should not rely on the secrecy of its algorithms (including API endpoints). See http://en.wikipedia.org/wiki/Kerckhoffs's_principle

over 1 year ago ·