5. Modules

In the Node.js servers and scripts you have written thus far, you have already consumed external functionality in the form of modules. In this chapter, I explain how this all works and how to write your own. In addition to all the already-powerful and functional modules that Node provides for you, there is a huge community further developing modules that you can take advantage of in your programs, and indeed you can even write your own to give something back!

One of the cool things about Node is that you don’t really distinguish between modules that you have produced and modules that you consume from external repositories, such as those you see later in this chapter via npm, the Node Package Manager. When you write separate classes ...

Get Learning Node.js: A Hands-On Guide to Building Web Applications in JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.