Integrating Sails Js with Angular 2 Integrating Sails Js with Angular 2 angularjs angularjs

Integrating Sails Js with Angular 2


You need to setup access to your static files. You can check out how, right here. http://sailsjs.org/documentation/concepts/assets

So put those node modules into an asset folder, for which you can then have static access.

However, are you sure you want to do this with Sails? As far as I know Sails is a fullblown MVC framework, which you won't really need if you only want to use it as a backend for Angular. I'd recommend using something like Express instead.


So, for anyone interested, i have resolved the issues like so:

1 - For providing static access to node_modules i created an express middleware (probably use policies for this as well?):

(config/express.js)

var express = require('express');module.exports.http = {customMiddleware: function (app) {    app.use('/node_modules', express.static(process.cwd() + '/node_modules'));   }};

2 - I was able to compile already so all good there

3 - For the rxjs related errors, i did some research and found out that rxjs is no longer bundled with angular 2. Therefor, i had to modify the systemjs config a bit to add mapping for rxjs, like so:

(views/layout.ejs)

System.config({          map: {              rxjs: 'node_modules/rxjs' // added this map section          },          packages: {              app: {                  format: 'register',                  defaultExtension: 'js'              },              'rxjs': {defaultExtension: 'js'} // and added this to packages          }      });System.import('/app/main')              .then(null, console.error.bind(console));


You can use the JavaScript files that are provided in the folder node_modules/angular2/bundles:

<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script><script src="node_modules/systemjs/dist/system.src.js"></script><script src="node_modules/rxjs/bundles/Rx.js"></script><script src="node_modules/angular2/bundles/angular2.dev.js"></script><script src="node_modules/angular2/bundles/router.dev.js"></script><script src="node_modules/angular2/bundles/http.dev.js"></script>

This should answer to your first question.

Regarding the second question, elements you put in the scripts block of your package.json file are aliases for commands. The tsc -w one waits for updates in TypeScript files and automatically compiles them. This command must be started in background... For example with: npm run tsc:w.

Hope it helps you,Thierry