海洋饼干

Introduction to Node.js (Part 1)

Prerequisites:

Welcome to the world of Back-end web development. Before we dive deep into the topic, let us brush up the prerequisites. A website has 2 parts, the "Front-End" and the "Back-End". The Front-end of a website generally refers to the side of the website with which the user interacts. It's the User Interface(U.I.) of the website. In simple terms, it consists of all those elements which we see and interact with after the web page loads in our computer. It is sometimes also known as "Client-side" of the web page. The Back-end development refers to the server-side development that is back-end is about all the activities happening behind the scenes of a website.

Now, what happens actually behind the scenes? The back-end of a website consists of a server, an application and a database, mainly focuses on databases, scripting, and the architecture of websites. When we type a URL in our browser, a request goes to DNS server. The DNS resolve the IP for the URL and send it to the browser so that browser can request that host for the website. To some extent, we can conclude servers as the heart of the network. Databases are responsible for storing data and it is from where the data is rendered to the client-side. It is much like the brain of the network. A database server is a server which provides database services to computers and other computer programs, as defined by the client–server model. Likewise, an application server is a software framework that provides both facilities to create web applications and a server environment to run these applications. It has to be remembered that database and database server is not the same thing. Similarly, an application and an application server is also different.

Introduction:

Now, we come to the main topic. As per the Node.js official documentation, Node.js is a JavaScript runtime built on Chrome's V8 JavaScript engine. Before you mess up with the terms used here, let me explain what the official definition actually means by breaking it into small parts. When we run a JavaScript code or work with any JavaScript frameworks, the code gets executed in the browser. So, in that case our browser is the JavaScript runtime. The JavaScript(JS) code is converted into machine code with the help of a JavaScript parser. In case of Google Chrome, it's V8, for Firefox it's SpiderMonkey and for Microsoft Edge it's Chakra. There are couples of libraries on which Node.js depends to work properly.

Most important are: Chrome's V8 & LIBUV.

If V8 was not there then Node.js had no way to understand, the JS code we write in the Node.js environment. LIBUV is an opensource library with strong focus on asynchronous I/O. this gives access to OS, file system, networking and more. This is also responsible for 2 main features of Node.

1. The Event Loop.

2. The Thread Pool.

Apart from all of this, Node.js also depends on:

1. http-parser for parsing http.

2. c-ares for some DNS request staff.

3. OpenSSL for cryptography.

4. zlib for compression.

We will discuss all of the above points in the upcoming posts. But let us first focus on the primary idea. In simple words, Node.js lets developers use JavaScript to write command line tools and for server-side scripting-running scripts server-side to produce dynamic web page content before the page is sent to the user's web browser.

Characteristics of Node.js:

1. Fast, efficient and highly scalable.

2. Event driven, non-blocking I/O Model.

3. Asynchronous in nature.

4. Single Threaded.

5. It's Open Source.

6. We use only one language at both ends of the website.

Hope you like the Introduction to Node.js (Part 1). To learn more follow the next blog Introduction to Node.js (Part 2)