Dustin Sun
Dustin Sun

Reputation: 5532

Angular2 working with NodeJs

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?

Upvotes: 0

Views: 2382

Answers (4)

Evan Plaice
Evan Plaice

Reputation: 14140

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.

Upvotes: 0

Vinci Rufus
Vinci Rufus

Reputation: 1

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

Upvotes: 0

user2379441
user2379441

Reputation: 148

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.

Upvotes: 0

Felix D.
Felix D.

Reputation: 2220

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).

Upvotes: 4

Related Questions