简体   繁体   English

使用Node JS进行前端

[英]Use of Node JS for Frontend

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. 我听说Node.js在应用程序的前端使用而不是后端,但我找不到任何可以使用它的用例。 Can somebody explain the use cases for which Node.js is used in the frontend. 有人可以解释在前端使用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 提前致谢

Node.js is a javascript runtime that uses the Chrome V8 javascript engine. Node.js是一个使用Chrome V8 javascript引擎的javascript运行时。 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. 前端已经在浏览器上使用了javascript引擎(适用于Chrome的V8,适用于Firefox的SpiderMonkey,适用于Edge的Chakra),因此无论Javascript是否在Node.js中的浏览器中运行,您都可以期待非常类似的环境。

However, you might be interested in using Node.js modules on the front-end. 但是,您可能有兴趣在前端使用Node.js模块。 The modules are packaged using a tool called npm . 这些模块使用名为npm的工具打包。 You can use module loaders or bundlers like Browserify , webpack , or Rollup.js to accomplish this. 您可以使用模块加载器或Bundify ,如BrowserifywebpackRollup.js来完成此任务。

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. 开发前端应用程序时,您通常会将Node.js及其生态系统用作工具链的一部分,但部署的应用程序仍然是在用户浏览器中运行的常规JavaScript。 You can use Node's package manager npm instead of Bower for managing your frontend dependencies, for instance. 例如,您可以使用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包。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM