This is the fifth day of my participation in Gwen Challenge
What can Node.js bring us?
If you have some front-end basics, such as HTML, CSS, JavaScript, jQuery; Node.js, then, allows you to quickly transition to being a full-stack engineer at the lowest cost, touching back end and mobile development. Of course, Node.js is not a panacea, nor does it mean that learning it can completely replace other backend development languages. It has its own mission and application areas of expertise.
Like the current hot vue.js, Rect… Node.js is preferred for many data layer dynamic interactions. So, that’s one more reason why you should study it.
Node.js and traditional back-end languages (such as PHP, JSP, etc.) have their own advantages and disadvantages, different areas of expertise and focus, so each has its own strengths and needs. Node.js gives us an easy way to do back-end development.
What is Node.js good at doing and not good at doing in development?
2.1 What Node.js is good at doing
The first category: background management system, real-time interactive system, networking software, high concurrency Web applications;
The second category: web, Canvas and other multiplayer online games;
The third category: Web-based multiplayer real-time chat client;
Fourth category: single-page browser applications;
Fifth category: working with databases and providing JSON-based apis for front-end and mobile applications;
The sixth category,….
Take a peek at Node.js with the live chat client:
-
Unified Protocol Ports: Starting with IRC, there are many open and non-open protocols that run on non-standard ports. Using Node.js, WebSockets run on standard port 80.
-
Less complex computing: lightweight, high traffic, and good at running data-intensive devices across platforms.
-
Object database interface: Node.js is very suitable for querying data through object database (such as MongoDB). Data stored in JSON format allows Node.js to process it directly without the hassle of converting and matching data.
-
Queue input: Chat applications deal with high volumes of concurrent data, and Node.js’s queue output solves this problem by acknowledging that the client’s data is real before it’s actually written. (Common practice in development is that such time-consuming operations are handled asynchronously through callbacks and the main thread continues to execute.)
-
Data stream receives data: We can process uploaded files online because data is received as a stream. So real-time audio and video can be done on a web page, without having to go through an app.
2.2 What Node.js is not good at
The first category: server-side WEB applications that use relational databases;
Because express.js is not currently sufficient to support all development requirements.
Category 2: applications with heavy server computing and processing.
Anything involving CPU-intensive operations negates the throughput advantages Node offers through event-driven, asynchronous I/O models, and so on, because any incoming requests will be blocked when threads are tied up in non-asynchronous high computation.
What is Node.js?
Node.js is a wrapper around the Google V8 engine, the Libuv platform abstraction layer, and the main body of the core library written in Javscript, making heavy use of the event-driven asynchronous development. In addition, the real-time Web application uses the websocket-based push technology, the client and server can initiate communication, can freely exchange data. Very elegant and practical through the front and back ends.
V8, developed by Google, is currently recognized as the fastest Javascript parsing engine with server-side parsing capabilities. Libuv is an open source, cross-platform asynchronous IO library customized for Node.
How does Node.js work?
Node.js is best used for high-performance, scalable Internet applications – because it can handle large and high-throughput concurrent connections. This is mainly due to the following features of Node.js:
Event-driven Event driven
Non-blocking asynchronous I/O call
Lightweight Saves space and equipment. Lightweight means better portability
Node.js is a cross-platform project that runs on Linux, Unix, and Windows
Efficient (Node.js is based on single threads)
In PHP or JSP, each new connection (request) creates a new thread that consumes system memory and eventually consumes all available memory. Node.js, on the other hand, only runs in a single thread, uses non-blocking asynchronous I/O calls, all connections are handled by that thread, and libuv allows it to support tens of thousands of concurrent connections (all hanging in the thread’s event loop).
Note: Node.js also has potential pitfalls. For example, if all client requests share a single thread, a large number of computations may cause Node’s single thread to temporarily become unactive and cause all other client requests to block until the computation is complete.
Therefore, never allow an Exception to block the core event loop at development time, as this will cause the Node.js application to crash. For example, in PHP, a web site will not be affected if a page dies, but Nodejs handles all links thread by thread, so any abnormal blocking could affect all other links.
Of course, Node.js has a lot of tools and strategies to help us solve these problems, such as exception callback passing, process monitoring with Forever, and so on
Four, conclusion
If your project requirements don’t include CPU intensive operations and don’t require access to any blocking resources, then you can take advantage of Node.js to develop any web application as fast, fast, and scalable as you want.
Because Node.js was never created to solve large-scale computing problems. It was created to solve the problem of large-scale I/O, and it does this very well.
As you continue to develop Node.js, you’ll find that most of the problems are caused by the misuse of blocking operations. Therefore, be very careful to avoid this problem.