- Hands-On Machine Learning with JavaScript
- Burak Kanber
- 776字
- 2021-06-25 21:38:18
Node.js
The release of Node.js in 2009 is possibly the single most important moment in JavaScript's history, though it would not have been possible without the release of the Chrome browser and Chrome's V8 JavaScript engine in the previous year.
Those readers who remember the launch of Chrome also recognize why Chrome dominated the browser wars: Chrome was fast, it was minimalist, it was modern, it was easy to develop for, and JavaScript itself ran much faster on Chrome than on other browsers.
Behind Chrome is the open source Chromium project, which in turn developed the V8 JavaScript engine. The innovation that V8 brought to the JavaScript world was its new execution model: instead of interpreting JavaScript in real time, V8 contains a JIT compiler that turns JavaScript directly into native machine code. This gambit paid off, and the combined effect of its stellar performance and its open source status led others to co-opt V8 for their own purposes.
Node.js took the V8 JavaScript engine, added an event-driven architecture around it, and added a low-level I/O API for disk and file access. The event-driven architecture turned out to be a critical decision. Other server-side languages and technologies, such as PHP, typically used a thread pool to manage concurrent requests, with each thread itself blocking while processing the request. Node.js is a single-threaded process, but using an event loop avoids blocking operations and instead favors asynchronous, callback-driven logic. While the single-threaded nature of Node.js is considered by many to be a drawback, Node.js was still able to handle many concurrent requests with good performance, and that was enough to bring developers to the platform.
A few months later, the npm project was released. Building on top of the foundational work that CommonJS achieved, npm allowed package developers to publish their modules to a centralized registry (called the npm registry), and allowed package consumers to install and maintain dependencies with the npm command-line tool.
Node.js likely would not have broken into the mainstream if not for npm. The Node.js server itself provided the JavaScript engine, the event loop, and a few low-level APIs, but as developers work on bigger projects they tend to want higher-level abstractions. When making HTTP requests or reading files from disk, developers don't always want to have to worry about binary data, writing headers, and other low-level issues. The npm and the npm registry let the developer community write and share their own high-level abstractions in the form of modules other developers could simply install and require().
Unlike other programming languages which typically have high-level abstractions built in, Node.js was allowed to focus on providing the low-level building blocks and the community took care of the rest. The community stepped up by building excellent abstractions such as the Express.js web application framework, the Sequelize ORM, and hundreds of thousands of other libraries ready to be used after just a simple npm install command.
With the advent of Node.js, JavaScript developers with no prior server-side language knowledge were now able to build entire full-stack applications. The frontend code and backend code could now be written in the same language, by the same developers.
Ambitious developers were now building entire applications in JavaScript, though they ran into a few issues and solutions along the way. Single-page applications fully written in JavaScript became popular, but also became difficult to template and organize. The community responded by building frameworks such as Backbone.js (the spiritual predecessor to frameworks such as Angular and React), RequireJS (a CommonJS and AMD module loader), and templating languages such as Mustache (a spiritual predecessor to JSX).
When developers ran into issues with SEO on their single-page applications, they invented the concept of isomorphic applications, or codes that could be rendered both server side (so that web spiders could index the content) and client side (to keep the application fast and JavaScript-powered). This led to the invention of more JavaScript frameworks such as MeteorJS.
Eventually, JavaScript developers building single-page applications realized that often, their server-side and database requirements were lightweight, requiring just authentication, and data storage, and retrieval. This led to the development of serverless technologies or database-as-a-service (DBaaS) platforms such as Firebase, which in turn laid out a path for mobile JavaScript applications to become popular. The Cordova/PhoneGap project appeared around the same time, allowing developers to wrap their JavaScript code in a native iOS or Android WebView component and deploy their JavaScript applications to the mobile app stores.
For our purposes throughout this book, we'll be relying on Node.js and npm very heavily. Most of the examples in this book will use ML packages available on npm.
- Google Cloud Platform Cookbook
- 程序設計缺陷分析與實踐
- 手把手教你玩轉RPA:基于UiPath和Blue Prism
- Visual C++編程全能詞典
- RPA(機器人流程自動化)快速入門:基于Blue Prism
- JavaScript典型應用與最佳實踐
- 貫通Java Web開發三劍客
- 教育機器人的風口:全球發展現狀及趨勢
- Silverlight 2完美征程
- Artificial Intelligence By Example
- Mastering Text Mining with R
- 手把手教你學Flash CS3
- Linux常用命令簡明手冊
- 這樣用Word!
- Cloud Native Development Patterns and Best Practices