Why run JavaScript on the server side?

Because at the time, Ryan Dahl , the author of Node.js, was a senior C/C++ programmer. Before creating Node, his main work was around high-performance web servers. After some trial and error, he found several key points for designing high-performance, web servers: event-driven, non-blocking I/O .

So Ryan Dahl's original goal was to write an event-driven, non-blocking I/O based web server to achieve higher performance and provide an alternative to servers such as Apache. He mentioned that the main reason most people don't design a simpler and more efficient program is that they use a library that blocks I/O . When writing Node, Ryan Dahl evaluated languages ​​like C, Lua, Haskell, Ruby , etc. as alternative implementations, and concluded:

The development threshold of C is high, and it is foreseeable that not many developers can use it for daily business development, so it is abandoned;

Ryan Dahl felt he wasn't good enough to play Haskell, so he ditched it;

Lua itself already contains many blocking I/O libraries, and building a non-blocking I/O library for it cannot change the habit of people continuing to use blocking I/O libraries, so it is also abandoned;

Ruby's virtual machine was rejected due to poor performance.

In contrast, JavaScript has a lower development threshold than C, and less historical baggage than Lua. Although server-side JavaScript has existed for many years, there has been no market for the back-end part, arguably zero historical baggage, and no additional resistance to importing a non-blocking I/O library for it. In addition, JavaScript has a wide range of event-driven applications in browsers, which coincides with Ryan Dahl's preference for event-driven needs. At that time, the second browser war was gradually divided, and the JavaScript engine V8 of the Chrome browser won the top performance, and it was released based on the new BSD license, which was naturally welcomed by Ryan Dahl. Taking into account the three main reasons of high performance, event-driven, and no historical baggage , JavaScript has become the implementation language of Node.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325173527&siteId=291194637