admin管理员组文章数量:1417660
I'm just beginning to read the angular2 quickstart and notice it is using npm, node and typescript. I was wondering what is the use of node.js in angular2? Isn't angular just a client side framework? So what is the use of node.js and what is node.js exactly doing? In the quickstart, it doesn't show you how to use angular2 without node.js. So I'm a bit confused since in my mind angular is just a client side framework.
Thanks for the clarification.
I'm just beginning to read the angular2 quickstart and notice it is using npm, node and typescript. I was wondering what is the use of node.js in angular2? Isn't angular just a client side framework? So what is the use of node.js and what is node.js exactly doing? In the quickstart, it doesn't show you how to use angular2 without node.js. So I'm a bit confused since in my mind angular is just a client side framework.
Thanks for the clarification.
Share Improve this question asked May 26, 2016 at 14:01 pdiddypdiddy 6,30710 gold badges53 silver badges114 bronze badges3 Answers
Reset to default 7Angular2 is a client side framework, it doesn't need nodejs in order to work. The confusion es from typescript, because the typescript piler runs on nodejs. Note that typescript supports ES6 which introduced the support for modules that have import and export functionality.
NodeJS became inseparable part of the front-end development cycle since it provides many tools for building apps, task runners, pilers, test frameworks etc. .
PS: There is an angular documentation dedicated for javascript: link
You can switch the languages from the dropdown menu under the main header. Sadly, at the moment most of the documentation is written only for Typescript. You can download already piled source of angular2 and start using it without node.
Fact: Sure, angularJS is a client side framework. But NODEJS is not a sever side framework, it is a platform which provides JavaScript Runtime Environment.
Why NodeJS is being used in Client Side Development:
- It provides instant access to all the JS libraries(e.g Angular) to be used in the web page, with the help of npm (Node Package Manager). Thus, install any required library using
npm install package_name --save
. So, no need to learn bower. - One can write build scripts and create watchers. Thus, no need of Gulp or Grunt.
- One can install any live-reload node module for live reload the changes made in your client app.
NODEJS used in Angular2 (JavaScript) Documentation:
- Created a
package.json
file which contains all the required libraries for the client app. - Next simply hit
npm install
and all the required libraries are downloaded in your local machine undernode_modules
folder. - thus:
<script src="node_modules/@angular/core/core.umd.js"></script>
- Installs a node module called:
lite-server
which serves your web app and live reloads it on changes. It is executed bynpm start
check the script section in package.json. - Thus, for futher development you just need to focus on your app and for downloading any client side libraries one can use like:
npm install jQuery --save
At the end of the day, NODEJS just makes your life easier with just one package.json file.
The reason I think that Angular2 is provided as an NPM module is because of the TypeScript pilation.
The piler requires d.ts
files for module contracts. Moreover when you specify the moduleResolution
attribute to node
in the tsconfig.json
file, it will load them through Node:
{
"pilerOptions": {
"target": "es5",
"module": "monjs",
"moduleResolution": "node", // <-----
"sourceMap": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"removeComments": false,
"noImplicitAny": false
},
"exclude": [
"node_modules",
"typings/main",
"typings/main.d.ts"
]
}
That being said, Node isn't used within the Angular2 application itself when executing within the browser.
本文标签: javascriptAngular2 and nodejsStack Overflow
版权声明:本文标题:javascript - Angular2 and node.js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745276350a2651211.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论