January 2018
Intermediate to advanced
336 pages
7h 22m
English
Let’s enhance our file-watching example program even further by having it spawn a child process in response to a change. To do this, we’ll bring in Node.js’s child-process module and dive into some Node.js patterns and classes. You’ll also learn how to use streams to pipe data around.
To keep things simple, we’ll make our script invoke the ls command with the -l and -h options. This will give us some information about the target file whenever it changes. You can use the same technique to spawn other kinds of processes, as well.
Open your editor and enter this:
| | 'use strict'; |
| | const fs = require('fs'); |
| | const spawn = require('child_process').spawn; |
| | const filename = process.argv[2]; ... |
Read now
Unlock full access