When we learn something new, we first need to know where it comes from. What is it? What can be done or, in other words, what can be solved? No one thing is best, no one thing can replace everything, but it is best in a certain area, like Node.js. It may be something that some programmers are looking for, or it may be something that some programmers don’t care about. This article will give you a background on Node.js and what it does and is good at. It won’t get into the complicated code level, but you can ignore it if you think you’re familiar with it.
About the author: Jun May, Nodejs Developer, a post-90s youth who loves technology and likes sharing. The public account “Nodejs Technology Stack”, Github open source project www.nodejs.red
At the end of the article, the author recently organized the Node.js technology stack learning guide roadmap for your reference!
background
Node.js® is a JavaScript Runtime built on Chrome’s V8 JavaScript engine. Node.js is a JavaScript runtime environment based on the Chrome V8 engine. Node.js is not a new programming language. As a beginner, it is the runtime environment of JavaScript, and more specifically, the runtime environment on the server side. So by programming language I mean JavaScript.
Back in 2009, JavaScript was still a scripting language running in the browser environment. At that time, the author was still a high school student with VB programming language and did not know what JavaScript was. But then I got into JavaScript and realized that before that you could write some browser scripts and do some dynamic effects, mostly for front page interaction. Since the 2009 timeline Javascript has run not only in browsers but also on servers, bridging the front and back ends, thanks to Ryan Dahl, the creator of Node.js. I used to think this was great, of all the programming languages, why JavaScript? Look at the following introduction.
Why JavaScript?
Node.js uses an event-driven, non-blocking I/O model, making it lightweight and efficient. This is another introduction from Node.js, event-driven, non-blocking I/O. Therefore, after evaluating C, Lua, Haskell, Ruby, JavaScript and other languages based on these conditions, Node.js author Ryan Dahl, I ended up with JavaScript. Why?
JavaScript is a single-threaded language. The advantage of single-threaded language is that unlike Java and other multi-threaded languages, thread synchronization and thread locking problems occur during programming, and performance overhead caused by context switch is also avoided. In fact, it can only be single-threaded in the browser environment. Imagine a scenario where multiple threads operate on the same DOM. Isn’t that a mess? So one of the problems you might think about with single threads is, isn’t the first one going to get stuck? Of course not. JavaScript is an event-driven, asynchronous callback model, and JavaScript has no historical baggage on the server side. On virtual machines, thanks to Chrome V8, Making JavaScript the language of choice for Node.js.
Why JavaScript author Ryan Dahl should be the best to say, here is some information and reference to the simple book Node.js, for everyone to have a preliminary understanding.
Node. Js framework
Node.js consists of Libuv, Chrome V8, and some core apis, as shown below:
The above shows the structure of Node.js, and the following is a brief explanation:
-
Node Standard Library: Node.js provides JavaScript interfaces, such as HTTP, buffer, FS, and Stream modules
-
Node bindings: this is the bridge between JavaScript and C++, which encapsulates the lower module and provides the basic API interface to the upper layer.
-
V8: Google’s open-source, high-performance JavaScript engine, developed in C++ and running in Google chrome. If you are interested in learning more about V8 engines, visit What is V8?
-
Libuv is a cross-platform event-driven I/O library. It was developed for Node.js using C and C++ and is a core part of I/O operations, such as reading files and OS interaction. From a Libuv Chinese tutorial
-
C-ares: C-ARES is an asynchronous DNS resolution library
-
Low-level Components: Provides HTTP parsing, OpenSSL, data compression (Zlib), and other functions.
The above is just a snapshot, but each of these points is worth exploring if you want to learn more about Node.js.
A reference from Stack Overflow: which-is-correct-node-js-architecture
Node. Js characteristics
Now that we know some of the background and architectural models of Node.js, where does it come from? What is? This problem, now let’s see what can we solve? What is it good for?
I don’t know if you’ve heard before, but Node.js is good at I/O intensive tasks, and it’s good for some OF the I/O intensive, high-concurrency scenarios, and that’s where it’s positioned: to provide a simple and secure way to build high-performance and scalable web applications in JavaScript.
- Single thread
Node.js uses a single thread to run, rather than producing one thread per request to other servers such as Apache HTTP. This approach avoids CPU context switching and large execution stacks in memory, which Nginx and other servers have been trying to solve for the last 10 years. Famous C10K concurrent connection problem “while adopting the method.
- Non-blocking I/O
Node.js eliminates the need to wait for input or output (database, file system, Web server…) CPU time lost in response, thanks to Libuv’s powerful asynchronous I/O.
- Event-driven programming
Events and callbacks are common in JavaScript, and this kind of programming may be difficult to understand for students who are accustomed to synchronous thinking, but it is a high-performance service model. Node.js and Nginx are both event-driven. The difference lies in that Nginx is written in pure C and only applicable to Web servers, while Node.js is an extensible and high-performance platform for business processing.
- cross-platform
Initially Node.js was only available on Linux, but after v0.6.0 it was available on Windows thanks to Libuv support.
What does Node.js work for
With all that said, where does Node.js fit in?
- I/O intensive scenario
The main advantage of Node.js is the event loop, non-blocking asynchronous I/O, only one thread, I don’t have to create a thread for every request, resulting in resource overhead.
- ResutFul API
Node.js is usually used as the middle layer, which is responsible for assembling data and providing API interfaces to the front-end calls. These data sources may come from third-party interfaces or databases, for example, we might have done this through back-end Java, PHP, or other languages. Now we front-end engineers can do it with Node.js, and the back end can focus more on business development.
Here is a useful API management tool from github.com/YMFE/yapi, which is developed using Node.js. Here is a useful API management tool from github.com/YMFE/yapi. Can not help but recommend to everyone! .
- The RPC service
Remote Procedure Call (RPC) Chinese name “Remote Procedure Call”, maybe you are very unfamiliar with it, but in today’s micro-service mode, we may be servitization for functions or specific business forms, so we all know that HTTP is a common mode of communication between services. Those of you who know the network model probably know, wouldn’t it be more efficient if we went through TCP now?
Of course, HTTP belongs to the application layer protocol, below which is the transmission layer. Obviously, TCP is very advantageous. RPC service is also the TCP adopted, and now famous RPC services such as Google gRPC and Ali Dubble.
- The fundamental tools
It can be used as a base tool, compiler, build tool, scaffolding, etc. The better-known ones like Webpack and Gulp are very successful.
- BBS community
Nodeclub is a community system developed using Node.js and MongoDB, with elegant interface, rich functions, small and fast, you can use it to build your own community. One successful example is the Cnode community, cnodejs.org/
Github.com/cnodejs/nod…
- Backend For Frontend
Backend For Frontend (BFF For short) serves the back-end of the Frontend. Backend is not a new technology but a logical layer on which resources can be consolidated, For example: In the past, the front end needed to obtain resources from three different places, so with this layer, can we make an aggregation, unified processing and then return to the front end, while not giving changes to the back-end system, resulting in changes.
- Serverless
ServerLess is a “ServerLess architecture” that doesn’t require developers to care about operations, traffic handling, etc. Developers can focus on the business itself.
Function is a service, so writing a function can realize an API interface to the front end, obviously to the development work is reduced a lot, in JavaScript function is a first-class citizen, ServerLess in this scenario Node.js itself is also very lightweight, or has a great advantage.
- Microservices
Microservices are also a hot word in the past two years. Here are some main features of microservices: small services, independent process running, can use different languages. Node.js is also very lightweight and fast to implement. It is also suitable for some I/O intensive scenarios.
What scene to choose what tools, there is no best only more appropriate!
Why node.js
Talking about some personal feelings and experiences, in fact, it is neither too late nor too early to get into the computer industry. I started to learn programming in high school and learned many programming languages before CONTACTING Node.js. The general curve is like this: VB (in high school), C, C#(.NET), Java, PHP, all of these are nothing to play with when I was in school. There are also contact with the front end, which is really complicated, but none of them are proficient, which is also the most terrible. In the summer vacation of my junior year, I went to a company in Beijing and practiced PHP for two months. But then I ran into someone who was doing Node.js, and I was like, wow, what is this thing that allows JavaScript to be the back end, which I haven’t seen in the market. Later, I did a simple understanding and began to learn Node.js after returning to school. I looked for various materials on the Internet and chose Node.js in this way until now, in fact, language is just a tool, such as in the back end, aside from the language layer, there are a lot of things we need to continue to learn.
One last piece of advice: do not set boundaries for yourself, for example: I must learn Node.js or I must learn Java or Python. In fact, if possible, you can touch other things more. On the one hand, you can expand your boundaries, and on the other hand, you can gain benefits from it.
Node.js Technology stack Learning Guide Roadmap
This is a recently drawn roadmap of the Node.js technology stack learning guide, showing that there is still much to learn beyond the language aspect. Welcome to pay attention to the public account “Nodejs technology stack” focus on node.js related technology stack research and share, if there are node.js related articles welcome to contribute! Grow together!