What is node.js used for?
I'm going to assume that I am explaining this to a total non-techie, so pardon me if I go into things that are a bit too rudimentary.
Are you familiar with Javascript? In case you're not, it's a web-based scripting language that's primarily used to manipulate the HTML of a page. So using Javascript, you can manipulate tables, divs, fonts, etc. to do things using traditional programming functionality. Javascript is known as a client-side language, and what this means is that the changes effected to a page through JS are seen only by you, the client. In other words, lets say you click on a button, and that button executes a Javascript command which changes the background colour of the website blue. That change in blue will only be seen by you, not by anyone else, and it will go away the moment you refresh. Why? Because Javascript interacts only with you, the client, and has no interaction with the server which actually hosts the background colour. Its usage are restricted to the page you are currently viewing, and your individual interactions with it. This is known generally as working on the front end.
On the other hand, you've got a language like PHP which interacts directly with a server. So in this case, clicking a button could execute a PHP script which actually goes into the server itself and changes the background color. Now the background colour has actually been changed on the back-end, and everyone who visits the website will see the changed background color. This is known as server-side scripting or the back end. PHP cannot directly manipulate the HTML on the page on a client-side basis.
Here's an example to illustrate the concept. Type this into your browser window (it won't do anything crazy, don't worry):
javascript:document.getElementsByTagName("body")[0 ].style.backgroundColor = "red";void(0);
Your page should now be red. This isn't a permanent change, and it only happens to you -- it'll go away on refresh. That's what Javacript does -- it changes/serves the stuff on your screen. Now compare that to, say, changing your password... that makes a permanentchange in the backend.
Node.js, in the simplest most basic terms, is a framework to develop server-side applications through JavaScript. Its usage are effectively limited to the advantages of the programming language JavaScript over alternative methodologies.
tl;dr - Node.js is effectively a server-side implementation of JavaScript. It allows you to, in a very nifty way, write the backend of the application in JavaScript.
I hope that helped.
No comments:
Post a Comment