为什么我们有install Node。js 2.0角吗?

时间:2022-11-01 22:24:46

I started a tutorial on Angular 2.0, the first step in setting up the workspace is installing Node.js and NPM.

我开始了一个关于角2.0的教程,设置工作空间的第一步是安装节点。js和NPM。

Why do we have install Node.js for Angular 2.0?

为什么我们有install Node。js 2.0角吗?

I don't remember doing this for angular 1.X.

我不记得用角1。x来做这个了。

4 个解决方案

#1


31  

Technically, Node.js and NPM are not needed to do Angular2 work. It does ease things though. Here's the main reasons I speculate are behind this choice:

从技术上讲,节点。不需要js和NPM做Angular2工作。但它确实缓解了问题。以下是我推测这一选择背后的主要原因:

  • TypeScript: the examples are .ts, and you need to run a compiler step to get them into .js, which can be done on-the-fly easily with Node.js and NPM (plus it's a way of easily getting typing files);
  • 打字稿:示例是.ts,您需要运行编译器步骤将它们转换为.js,这可以通过Node轻松地实时完成。js和NPM(另外,这是一种很容易获取输入文件的方法);
  • Web Server: serving your Angular SPA from a "real" albeit light web server prevents probably some nasty issues that come with checking your site using file:// links.
  • Web服务器:从一个“真实”的Web服务器上服务您的角度SPA,可以防止您使用文件://链接检查站点时出现的一些严重问题。

The Quickstart guide itself actually continues to mention some more concrete reasons as well:

Quickstart指南本身实际上也继续提到一些更具体的原因:

Here's what these scripts do:

下面是这些脚本的作用:

  • npm start - runs the compiler and a server at the same time, both in "watch mode"

    npm启动——同时运行编译器和服务器,都处于“监视模式”

  • npm run tsc - runs the TypeScript compiler once

    运行tsc -运行一次TypeScript编译器

  • npm run tsc:w - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them

    运行tsc:w -在监视模式下运行打字稿编译器;进程继续运行,等待对打字文件的更改,并在看到它们时重新编译

  • npm run lite - runs the lite-server, a light-weight, static file server with excellent support for Angular apps that use routing

    运行lite-运行lite-server,这是一个轻量级的静态文件服务器,对使用路由的有棱角的应用程序有很好的支持

  • npm run typings - runs the typings tool separately

    运行排版-分别运行排版工具

  • npm run postinstall - called by npm automatically after it successfully completes package installation. This script installs the TypeScript definition files defined in typings.json

    npm运行后安装——npm在成功完成包安装后自动调用。这个脚本安装在TypeScript .json中定义的定义文件

You can also have a look at the Quickstart source and further dive into where NPM is needed.

您还可以查看Quickstart源代码,进一步了解需要NPM的地方。


Footnote: there's a similar question about needing Node.js for AngularJS (1.x).

脚注:关于需要节点也有类似的问题。js AngularJS(1. x)。

#2


6  

Because Anglar2 is based on Typescript, Web Components and ES6 which need compilation for performance and broader browser support. Typescript is compiled to ES5 JavaScript and the other features require shims for backwards compatibility.

因为Anglar2基于打字稿、Web组件和ES6,需要编译才能获得性能和更广泛的浏览器支持。Typescript编译为ES5 JavaScript,其他特性都要求shims具有向后兼容性。

Since Typescript is a superset of JavaScript, and it's compiled to JavaScript anyway, you can write your code in plain JavaScript but it's not recommended.

由于Typescript是JavaScript的超集,并且已经编译成JavaScript,所以您可以用普通的JavaScript编写代码,但不推荐使用它。

For a more detailed explanation check out these videos on YouTube

想要更详细的解释,可以在YouTube上查看这些视频。

#3


1  

NodeJS gives you the tool npm that allows you to download libraries and packages you would use in Angular 2. From the shell you can go to your folder and type npm install to install dependencies you need to have installed to get your angular project going. It will make it easier for you! If you want a complete starter kit go to https://github.com/buckyroberts, you can fork or download the zip with all the starter files to get you going :)

NodeJS提供的工具npm允许您下载在角2中使用的库和包。从shell中,您可以进入您的文件夹并键入npm install,以安装您需要安装的依赖项,以使您的角度项目得以继续。这会让你更轻松!如果你想要一个完整的初学者工具包到https://github.com/buckyroberts,你可以用所有的启动文件把zip压缩或下载到:)

#4


0  

Even You do not need to use Node anywhere in production to use any front-end Javascript framework. whether it is jQuery, AngularJS, ReactJS, Angular2, etc.

甚至您也不需要在生产中任何地方使用Node来使用任何前端Javascript框架。无论是jQuery, AngularJS, tjs, Angular2等。

Angular2 can be used in isolation but to get and feel better development environment, angular2 should be used with nodejs and npm. Some of the nodejs modules helps you in web development.

Angular2可以单独使用,但是为了获得和感觉更好的开发环境,Angular2应该与nodejs和npm一起使用。一些nodejs模块可以帮助您进行web开发。

#1


31  

Technically, Node.js and NPM are not needed to do Angular2 work. It does ease things though. Here's the main reasons I speculate are behind this choice:

从技术上讲,节点。不需要js和NPM做Angular2工作。但它确实缓解了问题。以下是我推测这一选择背后的主要原因:

  • TypeScript: the examples are .ts, and you need to run a compiler step to get them into .js, which can be done on-the-fly easily with Node.js and NPM (plus it's a way of easily getting typing files);
  • 打字稿:示例是.ts,您需要运行编译器步骤将它们转换为.js,这可以通过Node轻松地实时完成。js和NPM(另外,这是一种很容易获取输入文件的方法);
  • Web Server: serving your Angular SPA from a "real" albeit light web server prevents probably some nasty issues that come with checking your site using file:// links.
  • Web服务器:从一个“真实”的Web服务器上服务您的角度SPA,可以防止您使用文件://链接检查站点时出现的一些严重问题。

The Quickstart guide itself actually continues to mention some more concrete reasons as well:

Quickstart指南本身实际上也继续提到一些更具体的原因:

Here's what these scripts do:

下面是这些脚本的作用:

  • npm start - runs the compiler and a server at the same time, both in "watch mode"

    npm启动——同时运行编译器和服务器,都处于“监视模式”

  • npm run tsc - runs the TypeScript compiler once

    运行tsc -运行一次TypeScript编译器

  • npm run tsc:w - runs the TypeScript compiler in watch mode; the process keeps running, awaiting changes to TypeScript files and re-compiling when it sees them

    运行tsc:w -在监视模式下运行打字稿编译器;进程继续运行,等待对打字文件的更改,并在看到它们时重新编译

  • npm run lite - runs the lite-server, a light-weight, static file server with excellent support for Angular apps that use routing

    运行lite-运行lite-server,这是一个轻量级的静态文件服务器,对使用路由的有棱角的应用程序有很好的支持

  • npm run typings - runs the typings tool separately

    运行排版-分别运行排版工具

  • npm run postinstall - called by npm automatically after it successfully completes package installation. This script installs the TypeScript definition files defined in typings.json

    npm运行后安装——npm在成功完成包安装后自动调用。这个脚本安装在TypeScript .json中定义的定义文件

You can also have a look at the Quickstart source and further dive into where NPM is needed.

您还可以查看Quickstart源代码,进一步了解需要NPM的地方。


Footnote: there's a similar question about needing Node.js for AngularJS (1.x).

脚注:关于需要节点也有类似的问题。js AngularJS(1. x)。

#2


6  

Because Anglar2 is based on Typescript, Web Components and ES6 which need compilation for performance and broader browser support. Typescript is compiled to ES5 JavaScript and the other features require shims for backwards compatibility.

因为Anglar2基于打字稿、Web组件和ES6,需要编译才能获得性能和更广泛的浏览器支持。Typescript编译为ES5 JavaScript,其他特性都要求shims具有向后兼容性。

Since Typescript is a superset of JavaScript, and it's compiled to JavaScript anyway, you can write your code in plain JavaScript but it's not recommended.

由于Typescript是JavaScript的超集,并且已经编译成JavaScript,所以您可以用普通的JavaScript编写代码,但不推荐使用它。

For a more detailed explanation check out these videos on YouTube

想要更详细的解释,可以在YouTube上查看这些视频。

#3


1  

NodeJS gives you the tool npm that allows you to download libraries and packages you would use in Angular 2. From the shell you can go to your folder and type npm install to install dependencies you need to have installed to get your angular project going. It will make it easier for you! If you want a complete starter kit go to https://github.com/buckyroberts, you can fork or download the zip with all the starter files to get you going :)

NodeJS提供的工具npm允许您下载在角2中使用的库和包。从shell中,您可以进入您的文件夹并键入npm install,以安装您需要安装的依赖项,以使您的角度项目得以继续。这会让你更轻松!如果你想要一个完整的初学者工具包到https://github.com/buckyroberts,你可以用所有的启动文件把zip压缩或下载到:)

#4


0  

Even You do not need to use Node anywhere in production to use any front-end Javascript framework. whether it is jQuery, AngularJS, ReactJS, Angular2, etc.

甚至您也不需要在生产中任何地方使用Node来使用任何前端Javascript框架。无论是jQuery, AngularJS, tjs, Angular2等。

Angular2 can be used in isolation but to get and feel better development environment, angular2 should be used with nodejs and npm. Some of the nodejs modules helps you in web development.

Angular2可以单独使用,但是为了获得和感觉更好的开发环境,Angular2应该与nodejs和npm一起使用。一些nodejs模块可以帮助您进行web开发。