Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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. Can somebody explain the use cases for which Node.js is used in the frontend.

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?

Thanks in advance

like image 321
Sahil Thakral Avatar asked Jan 24 '16 16:01

Sahil Thakral


2 Answers

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.

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.

like image 62
LanceLafontaine Avatar answered Oct 18 '22 07:10

LanceLafontaine


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.

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

like image 38
Franz Avatar answered Oct 18 '22 07:10

Franz