Chapter 5. Using Node.js within NW.js and Electron
This chapter covers
- Exploring Node.js
- Understanding the asynchronous nature of Node.js
- Managing events and streams
- Installing and using npm modules
- Packaging your apps with npm
Long before NW.js and Electron, a programming framework called Node.js was demoed by Ryan Dahl at JSConf in Berlin, showing a way to write and execute server-side JavaScript. Since that demo back in 2009, Node.js has spawned a huge ecosystem of libraries, applications, utilities, and frameworks (including NW.js and Electron). As a programming framework, it offers a different approach compared with other programming languages and their frameworks.
For those new to the world of Node.js, this chapter offers a gentle introduction to the programming framework and a chance to learn how to apply it not only when developing desktop apps, but also in other projects such as web apps. For those already familiar with Node.js, this chapter covers a lot of the ground that you might already be familiar with (the event loop, callbacks, streams, and node modules), so feel free to skip it.
One of the underrated features of both NW.js and Electron is the massive collection of packages available through Node.js’s package management tool, npm, that can be used for building desktop apps. This chapter will show how you can put Node.js to use when developing your desktop apps, as well as for organizing your code.