Using AngularJS as Front-End to Sails.js


Sails.js is a Node.js server-side MVC that I have successfully used in several mobile and web projects. Based on Express it natively offers views based on template engines such as EJS.

Single Page Applications

Single page applications (SPA) are better built with front-end frameworks that have more general capabilities going beyond templates. Being familiar with AngularJS with its enhanced HTML and two-way data binding, I decided to use AngularJS as the front-end to a server-side Sails.js.

AngularJS with Sails.js

An AngularJS app was constructed by deriving from angular-seed. The contents of the angular-seed/app folder was placed in the assets.

The Sails.js server listens on port 1337 (by default, but this could be configured), so the AngularJS app url was:
and voila, we have an AngularJS front-end to a Sails.js server.

To make API calls from the front-end to the server we use standard AngularJS $http or $resource. Because the front-end and server are hosted on the same domain and port there are no cross-domain issues. These calls go to the Sails.js controllers.