3 dicas para criar aplicativos angulares / de nó de nível empresarial

Acabei de criar o aplicativo piloto para ‘Policy Connect’, que é um aplicativo baseado na web para fornecer políticas legislativas para organizações do setor, como ‘Habitação’.

Este não é um estilo de mídia social descolado com gráficos sociais e sugestões preditivas sobre o estilo de roupa íntima que você pode gostar com base em seus seguidores – é uma ferramenta de negócios com conteúdo legislativo e de treinamento projetado para manter funcionários fora do hospital e empregadores cadeia!

Cenário

Mas adivinhe: ele é construído em AngularJS, Node e CouchDB, todos rodando em Heroku e Cloudant!

Então, aqui estão algumas dicas …

1. Faça seus controladores corretamente

Quase todo violino ou exemplo que vi define os controladores como uma função global. Não faça isso, pois não apenas polui sua janela global, mas também torna a minimização problemática. Você deve usar algo como:




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