Chapter 2. The basics of Node.js
This chapter covers
- Installing Node.js and using its module system
- Using package.json to describe your project’s metadata
- Using npm to install packages with npm install
- Doing two things at once with Node
- Using Node’s built-in http module to build a simple web server
In chapter 1, we described Node.js, explaining that it’s JavaScript, asynchronous, and has a rich set of third-party modules. If you’re like me, you didn’t totally understand these things when you first started with Node. This chapter aims to give the intro to Node that I wish I had: short and sweet. (From here forward, I’ll refer to Node.js simply as Node.)
Note
I’m assuming that you know a fair bit of JavaScript and that you don’t want an extremely thorough knowledge of Node from this chapter. I’m also going to assume that you have a working understanding of how to use the command line. If this whirlwind introduction to Node is a little too whirlwind, I recommend Node.js in Action by Mike Cantelon, et al. (Manning Publications, 2013) at www.manning.com/cantelon/.
Let’s get started.
A theme of the JavaScript world is an overwhelming number of choices, and Node’s installation is no exception; there are numerous ways to get Node running on your system.