admin管理员组

文章数量:1399926

When we talk about JavaScript vanilla it's frontend programming language; It needs a webserver like IIS, Apache or nginx etc to deliver the content to a client when requested. 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. What I know about node.js is its a runtime environment to make JavaScript work outside the browser; like for a backend api or regular desktop application.

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?

When we talk about JavaScript vanilla it's frontend programming language; It needs a webserver like IIS, Apache or nginx etc to deliver the content to a client when requested. 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. What I know about node.js is its a runtime environment to make JavaScript work outside the browser; like for a backend api or regular desktop application.

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?

Share Improve this question edited Jul 11, 2021 at 6:11 Gary 13.9k18 gold badges53 silver badges72 bronze badges asked Jul 11, 2021 at 4:35 adeladel 1258 bronze badges 4
  • because the framework is hosted on npm (npm is a node js package) – I_love_vegetables Commented Jul 11, 2021 at 4:38
  • @nCardot many frameworks and tons of usefull packages are hosted on the npm – I_love_vegetables Commented Jul 11, 2021 at 5:08
  • 1 The result of your framework does not need node to run. It will likely be static HTML + CSS + JS, calling some backend. But most modern JavaScript frameworks use node to serve (so you can develop in real time) and to build (which creates the minified static files used to run the site, once deployed). – tao Commented Jul 11, 2021 at 5:35
  • You don’t need node to run yow code, you need node to transpile yow code to a level where them browsers are able to run it, but if you use code that browsers understand, than no need for node – Ernesto Commented Jul 11, 2021 at 6:06
Add a ment  | 

2 Answers 2

Reset to default 8

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. For a few examples:

  • Webpack, to consolidate multiple script files into a single one for production (and to minify, if desired)
  • Babel, to automatically transpile scripts written in modern syntax down to ES6 or ES5
  • A linter like ESLint to avoid accidental bugs and enforce a consistent code style
  • A CSS preprocessor for Sass that can turn (concise) Sass into standard (more verbose) CSS consumable by browsers

And so on. Organizing an environment for these sorts of things would be very difficult without NPM (which depends on 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.

It's only for extra support during development, and ease of installing libraries. almost like an extra IDE / helpful editor

for example you might want to see changes you make on your HTML and frontend javascript code, without having to refresh the preview browser. 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.

that's all

本文标签: Why JavaScript frontend framework is needed for Nodejs to runStack Overflow