@@ -40,7 +40,7 @@ often won't run in the browser.
4040if}}
4141
4242If you want to follow along and run the code in this chapter, you'll
43- need to install Node.js version 10 or higher. To do so, go to
43+ need to install Node.js version 10.1 or higher. To do so, go to
4444[ _ https://nodejs.org _ ] ( https://nodejs.org ) and follow the installation
4545instructions for your operating system. You can also find further
4646((documentation)) for Node.js there.
@@ -151,8 +151,8 @@ Browser-related functionality, such as `document` or `prompt`, is not.
151151
152152{{index "Node.js", "global scope", "module loader"}}
153153
154- Beyond the few bindings I mentioned, such as ` console ` and ` process ` ,
155- Node puts few bindings in the global scope. If you want to access
154+ Beyond the bindings I mentioned, such as ` console ` and ` process ` ,
155+ Node puts few additional bindings in the global scope. If you want to access
156156built-in functionality, you have to ask the module system for it.
157157
158158{{index "require function"}}
@@ -344,7 +344,7 @@ The `npm` command is also used to publish new packages or new versions
344344of packages. If you ` npm publish ` in a ((directory)) that has a
345345` package.json ` file, it will publish a package with the name and
346346version listed in the JSON file to the registry. Anyone can publish
347- packages to NPM—though only under a new name, since it would be
347+ packages to NPM—though only under a package name that isn't in use yet , since it would be
348348somewhat scary if random people could update existing packages.
349349
350350Since the ` npm ` program is a piece of software that talks to an open
@@ -434,16 +434,16 @@ result (the second). As we saw in [Chapter ?](async), there are
434434downsides to this style of programming—the biggest one being that
435435error handling becomes verbose and error-prone.
436436
437- {{index "Promise class", "fs/ promises package"}}
437+ {{index "Promise class", "promises package"}}
438438
439439Though promises have been part of JavaScript for a while, at the time
440440of writing their integration into Node.js is still a work in progress.
441- There is a package called ` fs/ promises` in the standard library since
442- version 10, which exports most of the same functions as ` fs ` , but
441+ There is an object ` promises ` exported from the ` fs ` package since
442+ version 10.1 , which contains most of the same functions as ` fs ` , but
443443using promises rather than callback functions.
444444
445445```
446- const {readFile} = require("fs/promises") ;
446+ const {readFile} = require("fs").promises ;
447447readFile("file.txt", "utf8")
448448 .then(text => console.log("The file contains:", text));
449449```
@@ -489,6 +489,7 @@ let server = createServer((request, response) => {
489489 response.end();
490490});
491491server.listen(8000);
492+ console.log("Listening! (port 8000)");
492493```
493494
494495{{index port, localhost}}
@@ -863,7 +864,7 @@ and whether it is a ((directory)).
863864
864865``` {includeCode: ">code/file_server.js"}
865866const {createReadStream} = require("fs");
866- const {stat, readdir} = require("fs/promises") ;
867+ const {stat, readdir} = require("fs").promises ;
867868const mime = require("mime");
868869
869870methods.GET = async function(request) {
@@ -888,7 +889,8 @@ methods.GET = async function(request) {
888889
889890Because it has to touch the disk and thus might take a while, ` stat `
890891is asynchronous. Since we're using promises rather than callback
891- style, it has to be imported from ` fs/promises ` instead of ` fs ` .
892+ style, it has to be imported from ` promises ` instead of directly from
893+ ` fs ` .
892894
893895When the file does not exist ` stat ` will throw an error object with a
894896` code ` property of ` "ENOENT" ` . These somewhat obscure,
@@ -914,7 +916,7 @@ content type that the `mime` package gives us for the file's name.
914916The code to handle ` DELETE ` requests is slightly simpler.
915917
916918``` {includeCode: ">code/file_server.js"}
917- const {rmdir, unlink} = require("fs/promises") ;
919+ const {rmdir, unlink} = require("fs").promises ;
918920
919921methods.DELETE = async function(request) {
920922 let path = urlPath(request.url);
@@ -1085,7 +1087,7 @@ expression object.
10851087{{index "readFileSync function"}}
10861088
10871089Doing this synchronously, with ` readFileSync ` , is more
1088- straightforward, but if you use ` fs/ promises ` again to get
1090+ straightforward, but if you use ` fs. promises ` again to get
10891091promise-returning functions and write an ` async ` function, the code
10901092looks similar.
10911093
@@ -1127,7 +1129,7 @@ the _((WebDAV))_ standard, which specifies a set of conventions on top
11271129of ((HTTP)) that make it suitable for creating documents.
11281130
11291131``` {hidden: true, includeCode: ">code/file_server.js"}
1130- const {mkdir} = require("fs/promises") ;
1132+ const {mkdir} = require("fs").promises ;
11311133
11321134methods.MKCOL = async function(request) {
11331135 let path = urlPath(request.url);
0 commit comments