Cover by Guillermo Rauch

Safari, the world’s most comprehensive technology and business learning platform.

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required

O'Reilly logo

Chapter 5: CLI and FS APIs: Your First Application

This chapter examines some of the most essential Node.JS APIs: those related to the handling of stdin and stdout of a process (stdio) and those related to the filesystem (fs).

As discussed in the preceding chapter, the Node approach to concurrency inherently involves the use of callbacks and events. These APIs provide your first contact with the flow control involved in nonblocking evented I/O programming.

In addition to learning how all these APIs interact together, you create your first application: a simple command-line file explorer, whose goal is to allow the user to read and create files.

Requirements

Start by defining what you want your program to do:

You want the program to run on the command line. This means that the program is summoned either with the node command or by executing it directly, and then provides interaction with the user input and output through the terminal.

Upon starting, the program should display the list of current directories (see Figure 5-1).

9781119963103-fg0501.eps

Figure 5-1: List of current directories displayed at startup.

After you select a file, the program should output its contents.

After you select a directory, the program should display its children.

Then the program should quit.

Considering these cases, you can break down the project into different steps:

1. Creating our module

2. Deciding on sync ...

Find the exact information you need to solve a problem on the fly, or go deeper to master the technologies and skills you need to succeed

Start Free Trial

No credit card required