Basics of Node js P1

Tram Ho

1. What is Node.js?

  1. Node.js is a standalone development platform built on Chrome’s JavaScript Runtime that we can build network applications quickly and easily.
  2. Node.Js is an open source server environment. (open source server enviroment)
  3. Node.js is completely free.
  4. Node.js runs on many platforms (Windows, Linux, Unix. Mac OS X, etc.)
  5. Node.js uses javascript to run on the server environment.

2. Why use Node.js

Node.js uses an asynchronous programming language!

2.1 Here’s how PHP or ASP handles file requests

  1. Send the task to the computer file system (computer’s file system).
  2. Wait until the system opens and reads the file successfully.
  3. Returns information to the client.
  4. Prepare to be able to receive the next request.

2.2 This is how Node.js handles request files

  1. Send the task to the computer file system (computer’s file system).
  2. Prepare to receive the next request.
  3. Once the system has opened and read the file, the server will return content to the client.

Node.js eliminates the waiting and gets ready for the next request. Node.js runs single-threaded, non-blocking, asynchronous programming (single-threaded, non-blocking, asynchronously programming) for efficient memory usage.

3. Javascript

JavaScript is just a client-side programming language that runs in the browser, right? But this is no longer true. Node.js is a way to run JavaScript on the server; But it is more than that.

In a typical LAMP server environment (Linux-Apache-MySQL-PHP), you have a web server, Apache or NGINX, underneath, along with PHP running on it. Each connection to the server generates a new thread, and this makes the application quickly become sluggish or overloaded – the only way to support more users is by adding more servers. It simply doesn’t have good scalability. But with Node.js, this is not a problem.

JavaScript is an event-based language, so anything that happens on the server creates a non-blocking event. Each new connection generates an event; The data received from an upload form generates an event data-received; Querying data from the database also generates an event. In fact, this means that a Node.js website will never be locked up and can support tens of thousands of users to access it at the same time. Node.js plays the role of server – Apache – and interprets the application code that runs on it.


Share the news now

Source : Viblo