skip to Main Content

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?

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search