简体   繁体   English

为什么 Node.js 需要 JavaScript 前端框架才能运行?

[英]Why JavaScript frontend framework is needed for Node.js to run?

When we talk about JavaScript vanilla it's frontend programming language;当我们谈论 JavaScript vanilla 时,它是前端编程语言; It needs a webserver like IIS, Apache or nginx etc to deliver the content to a client when requested.它需要一个像 IIS、Apache 或 nginx 等的网络服务器来在请求时将内容传送到客户端。 After that, JavaScript runs on client browser, but every video or article I found said we need to install node.js to make this work.之后,JavaScript 在客户端浏览器上运行,但我发现的每个视频或文章都说我们需要安装 node.js 才能使其工作。 What I know about node.js is its a runtime environment to make JavaScript work outside the browser;我对 node.js 的了解是它的运行时环境使 JavaScript 在浏览器之外工作; like for a backend api or regular desktop application.就像后端 api 或常规桌面应用程序。

Here is my question: Why do we need to use Node.js if our target is to deploy a frontend webapp that's gonna run on the client browser?这是我的问题:如果我们的目标是部署将在客户端浏览器上运行的前端 web 应用程序,为什么我们需要使用 Node.js?

You don't have to install and use Node to make frontend applications, but it can help a lot, especially in large projects.不必安装和使用节点,使前端应用程序,但它可以有很大的帮助,尤其是在大项目。 The main reason it's used is so that script-writers can easily install, use, and update external packages via NPM.使用它的主要原因是脚本编写者可以通过 NPM 轻松安装、使用和更新外部包。 For a few examples:举几个例子:

  • Webpack, to consolidate multiple script files into a single one for production (and to minify, if desired) Webpack,将多个脚本文件合并为一个用于生产(如果需要,还可以缩小)
  • Babel, to automatically transpile scripts written in modern syntax down to ES6 or ES5 Babel,将现代语法编写的脚本自动转换为 ES6 或 ES5
  • A linter like ESLint to avoid accidental bugs and enforce a consistent code style像 ESLint 这样的 linter 避免意外错误并强制执行一致的代码风格
  • A CSS preprocessor for Sass that can turn (concise) Sass into standard (more verbose) CSS consumable by browsers Sass 的 CSS 预处理器,可以将(简洁)Sass 转换为浏览器可使用的标准(更详细)CSS

And so on.等等。 Organizing an environment for these sorts of things would be very difficult without NPM (which depends on Node).如果没有 NPM(这取决于 Node),为这些事情组织环境将非常困难。

None if it is necessary , but many find that it can make the development process much easier.没有必要,但许多人发现它可以使开发过程更容易。

In the process of creating files for the client to consume, if you want to do anything more elaborate than write plain raw .js , .html , .css files, you'll need something extra - which is most often done via NPM.在创建供客户端使用的文件的过程中,如果您想做比编写纯原始.js.html.css文件更复杂的事情,您将需要一些额外的东西 - 这通常是通过 NPM 完成的。

It's only for extra support during development, and ease of installing libraries.它只是为了在开发过程中提供额外的支持,以及易于安装库。 almost like an extra IDE / helpful editor几乎就像一个额外的 IDE/有用的编辑器

for example you might want to see changes you make on your HTML and frontend javascript code, without having to refresh the preview browser.例如,您可能希望查看对 HTML 和前端 JavaScript 代码所做的更改,而无需刷新预览浏览器。 node will provide a package that does that...节点将提供一个包来做到这一点......

it also helps install and use libraries easier.它还有助于更轻松地安装和使用库。 for example, if you want to add a library like bootstrap to your frontend, rather than searching around and downloading the files... but if you use node project, you can simply use npm install bootstrap that will automatically download the lastest version from the right source.例如,如果你想在你的前端添加一个像 bootstrap 这样的库,而不是四处搜索并下载文件……但是如果你使用 node 项目,你可以简单地使用npm install bootstrap ,它会自动从正确的来源。

that's all就这样

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

相关问题 为什么 Node.js 无法在终端中运行我的 JavaScript 代码? - Why Node.js cannot run my JavaScript code in the terminal? 将前端 Javascript 与后端 Node.Js 和 mySQL 集成 - Integrating Frontend Javascript with Backend Node.Js and mySQL Node.js上的Javascript FAB框架 - Javascript FAB framework on Node.js 为什么这个 javascript 会阻塞在 Node.js 中? - Why does this javascript block in Node.js? 为什么Node.js / JavaScript评估a:1到1? - Why does Node.js/JavaScript evaluate a:1 to 1? 如何在不使用框架的情况下通过Node.js将数据从MongoDB显示到前端 - How to display data from MongoDB to the frontend via Node.js without using a framework 为什么这个JavaScript代码在Node.js优化之后运行得更慢 - Why does this JavaScript code run slower after Node.js optimization 单击前端停止node.js中的功能 - Stop function in node.js with click in frontend 如何在 javascript 前端使用 async await 从 async await node.js 后端接收数据 - how to use async await on javascript frontend to receive data from async await node.js backend 如何使用 javascript(Reactjs) 作为前端和 node.js 作为后端创建依赖下拉列表 - How to create dependent dropdown list using javascript(Reactjs) as frontend and node.js as backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM