使用Node JS进行前端

时间:2021-10-08 01:11:51

I have heard about Node.js being used in the frontend side of the application as opposed to the backend side, but I cannot find any use cases for which it can be used. Can somebody explain the use cases for which Node.js is used in the frontend.

我听说过Node.js在应用程序的前端使用而不是后端,但我找不到任何可以使用它的用例。有人可以解释在前端使用Node.js的用例。

Also for a fairly complex system such as a CMS(Content Management System) for an e-commerce site, would Node.js be the right choice?

对于一个相当复杂的系统,如电子商务网站的CMS(内容管理系统),Node.js会是正确的选择吗?

Thanks in advance

提前致谢

2 个解决方案

#1


5  

Node.js is a javascript runtime that uses the Chrome V8 javascript engine. The front-end already uses a javascript engine on the browser (V8 for Chrome, SpiderMonkey for Firefox, Chakra for Edge), so whether Javascript is running in the browser on in Node.js, you can expect very similar environments.

Node.js是一个使用Chrome V8 javascript引擎的javascript运行时。前端已经在浏览器上使用了javascript引擎(适用于Chrome的V8,适用于Firefox的SpiderMonkey,适用于Edge的Chakra),因此无论Javascript是否在Node.js中的浏览器中运行,您都可以期待非常相似的环境。

However, you might be interested in using Node.js modules on the front-end. The modules are packaged using a tool called npm. You can use module loaders or bundlers like Browserify, webpack, or Rollup.js to accomplish this.

但是,您可能有兴趣在前端使用Node.js模块。这些模块使用名为npm的工具打包。您可以使用模块加载器或Browserify,webpack或Rollup.js等捆绑器来完成此任务。

#2


3  

You'd usually use Node.js and its ecosystem as part of your toolchain when developing frontend applications, but the deployed application will still be regular JavaScript that runs in the user's browser. You can use Node's package manager npm instead of Bower for managing your frontend dependencies, for instance.

在开发前端应用程序时,您通常会将Node.js及其生态系统用作工具链的一部分,但部署的应用程序仍然是在用户浏览器中运行的常规JavaScript。例如,您可以使用Node的包管理器npm而不是Bower来管理您的前端依赖项。

And there's Browserify which will let you use npm packages that were designed for Node in your frontend JavaScript application (that runs inside the user's browser).

还有Browserify,它允许你在你的前端JavaScript应用程序(在用户的浏览器中运行)中使用为Node设计的npm包。

#1


5  

Node.js is a javascript runtime that uses the Chrome V8 javascript engine. The front-end already uses a javascript engine on the browser (V8 for Chrome, SpiderMonkey for Firefox, Chakra for Edge), so whether Javascript is running in the browser on in Node.js, you can expect very similar environments.

Node.js是一个使用Chrome V8 javascript引擎的javascript运行时。前端已经在浏览器上使用了javascript引擎(适用于Chrome的V8,适用于Firefox的SpiderMonkey,适用于Edge的Chakra),因此无论Javascript是否在Node.js中的浏览器中运行,您都可以期待非常相似的环境。

However, you might be interested in using Node.js modules on the front-end. The modules are packaged using a tool called npm. You can use module loaders or bundlers like Browserify, webpack, or Rollup.js to accomplish this.

但是,您可能有兴趣在前端使用Node.js模块。这些模块使用名为npm的工具打包。您可以使用模块加载器或Browserify,webpack或Rollup.js等捆绑器来完成此任务。

#2


3  

You'd usually use Node.js and its ecosystem as part of your toolchain when developing frontend applications, but the deployed application will still be regular JavaScript that runs in the user's browser. You can use Node's package manager npm instead of Bower for managing your frontend dependencies, for instance.

在开发前端应用程序时,您通常会将Node.js及其生态系统用作工具链的一部分,但部署的应用程序仍然是在用户浏览器中运行的常规JavaScript。例如,您可以使用Node的包管理器npm而不是Bower来管理您的前端依赖项。

And there's Browserify which will let you use npm packages that were designed for Node in your frontend JavaScript application (that runs inside the user's browser).

还有Browserify,它允许你在你的前端JavaScript应用程序(在用户的浏览器中运行)中使用为Node设计的npm包。