My understanding is that AngularJS including Angular2 is a client-side framework, while Node.JS is a server side platform. They should not cross. But all Angular2 tutorials I found use Node/NPM. Why is that?
-
Most likely Node modules are used as part of the build process / dev environment. If you want specific answers though, you'll have to ask a more specific questionPhil– Phil2015-10-06 02:27:53 +00:00Commented Oct 6, 2015 at 2:27
-
Just don't worry about those tutorials. Those are for an easy start. A true project is way more complex and simple npm install does resolve the problem initially, but then bundling and configuring all of them using a packager such as webpack or gulp is a different story altogether. Starting off with a pre-built angular2 seed is fine, but you will lose out on better understanding and best practices then. Most of the seeds still don't follow basic component and sub-component design.user2379441– user23794412015-10-14 08:35:37 +00:00Commented Oct 14, 2015 at 8:35
4 Answers
Because npm is a package manager for packages written in JavaScript, and JavaScript can run both on client and server side. In other words, frontend and backend applications can both benefit from packages. Many development tools also use node as an underlying process (e.g. Jest-cli).
1 Comment
I would suggest you to use angular2 only on client side. The performance of angular2 really shines when it comes to handling view containers over regular server side codes. On the NodeJS side, I would recommend using es6 features. Which has revolutionised how you can not only code, but also performance.
Comments
The reason you see most tutorials using npm is because they are either using TypeScript or a build tool that uses Node to convert to ES5 or build your project. However you can still build Angular2 apps using the sfx version (self-executing bundle) of Angular2 and using ES5 syntaxes without having to use node or npm. Here is a blog post that shows how to do that http://blog.thoughtram.io/angular/2015/05/09/writing-angular-2-code-in-es5.html
Comments
Angular2 is a front-end framework but a lot of tooling that assists in building Angular2 applications are available via NPM.
If you want a package manager that's geared specifically to front-end development I suggest JSPM. It supports front-end modules of various formats (ie AMD, CommonJS, UMD), handles transpiling out of the box, and can be used as a build tool to concatenate/minify your application code.
You'll still need NPM for many other utilities and you'll need a back-end server for testing (I recommend live-server).
As far as the back-end is concerned. One of the Angular2 dev teams is working on a Node/Express extension that supports isomorphic rendering of JS. In short, it pre-renders the view on the server so the user can interact with it in the browser while the app loads in the background. The start time of launching a fully-featured SPA will still be kind of slow (relatively) but perceived speed will be instantaneous.