Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Porting the Setup Check

Porting the Setup Check

In this lesson, you ported the team’s setup check to JavaScript as its first Node project, ran it, and then found two slips a fast port makes.

  • Start the project folder with a package.json holding { "type": "module" }, so every .js file in it runs as a strict ES module.
  • Try each value at Node’s REPL before it goes in the file: process.versions.node, process.platform, and process.cwd() need no imports.
  • An unexpected undefined in the output, with no error, means a property name on that line is misspelled.
  • When the script stops, read the error from the top: the file and line, the caret, the error’s name and message, then the at lines.

Here’s the project’s package.json:

Language: JSON
{ "type": "module" }

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert JavaScript developers.

Unlock This Lesson

Already a member? Sign-In

00:02 In this project, you’ll port the team’s whole setup check to JavaScript and run it. Then you’ll break it the way a fast port does, and find each slip with what you’ve learned.

00:14 Here’s the team’s Python check. A function prints the Python version, the operating system and the folder, and a last line reminds the new developer to paste the report.

00:25 The team’s next steps are yours to port in the exercise after this video, so they stay folded here.

00:33 A JavaScript project starts with a folder and its package.json. Make the folder, onboarding-check, and move into it. Then create package.json with its one setting, type module.

00:48 Every JavaScript file in the folder now runs as a strict module, the way JavaScript developers start every project.

00:57 Before you write the file, try the three values at Node’s prompt, as you would at Python’s. Open the REPL in the project folder. Python’s version becomes process.versions.node, and the REPL echoes Node’s version.

01:14 The operating system is process.platform, and the folder is process.cwd(). Both echo the values the report needs, with no import.

01:27 Now write check-setup.js. The report function keeps its shape: function for def, and braces around the body. Each print() becomes console.log(), with the values you tried.

01:42 And the reminder goes to stderr with console.error(). The steps slot in later, in the exercise.

01:52 Run it in the project folder: node, then the file’s name. The report prints Node’s version, your operating system and the folder. The reminder comes last, on stderr.

02:07 Fast ports rarely run clean the first time. Say the version line lost one letter: process.version, with no s. In the undefined lesson, process.verison crashed.

02:21 What will this report’s first line say? Your turn: pause the video and predict.

02:32 Node, then undefined. The rest of the report prints, with no error at all.

02:40 Ask the REPL why. process.version is a real property, Node’s version as a string. A string has no node property, so reading it gives undefined.

02:54 An unexpected undefined means a misspelled property on that line. Put the s back.

03:02 Now the folder line gains a letter: console.logg. Run it, and two lines of the report print before it stops. Read it from the top. Line four, with the caret under logg.

03:18 A TypeError: console.logg is not a function. As in the undefined lesson, the misspelled property reads as undefined, and undefined can’t be called.

03:31 The next at line is its caller, line seven. Stop where Node’s frames begin. Fix the spelling, and the report runs again.

03:43 So here’s how you port, the JavaScript way. Start the folder as a module project, and try each value at the REPL before it goes in the file. When the output shows an unexpected undefined, check every property name on that line.

03:59 When it stops, read the error from the top. Next up is the exercise Finish the Setup Check, where you’ll port the team’s next steps and run the finished check.

Become a Member to join the conversation.