Intro to Node.js (concept)
Computer Science · JavaScript
Question 1 of 10
0Which built-in module lets a program run work in worker threads?
Stuck? Read the explanation
Unlocks at a streak of 5 correct answers in a row.
Embed this practice on your site or class page
Paste this HTML into your page. Students practise right there; it is free and needs no account.
Intro to Node.js (concept) explained
Node.js runs JavaScript outside the browser, on a computer or server. It uses the V8 engine that also powers Google Chrome, and it adds APIs for files, networks and processes, plus the npm registry of packages.
Node runs a script from top to bottom, but there is no document or window object. Instead it provides modules such as fs for files, http for web servers and path for file paths. Many of these APIs are asynchronous, so a slow file read does not block the rest of the program.
// app.js
console.log(process.argv.length);
const sum = process.argv.slice(2).map(Number).reduce((a, b) => a + b, 0);
console.log(sum);
Running node app.js 5 7 in a terminal passes the two extra words to the program through process.argv. Caveat: the first two entries of process.argv are the path to Node and the path to the script, so user input starts at index 2 and arrives as text, which must be converted with Number.
Worked example
For node app.js 5 7, process.argv holds four strings: the Node path, the script path, "5" and "7". Its length is 4. slice(2) keeps "5" and "7", Number converts them to 5 and 7, and reduce adds them to 12. The output is 4, then 12.
What you will practise
105 multiple-choice questions (Easy, Medium, Hard). Each answer is followed by an explanation.
Example questions
- Node.js runs JavaScript:
- Node.js is built on:
- Node uses an:
- npm installs:
- require() and module.exports:
- The command to run a JavaScript file named app.js with Node.js is:
- The file that describes a Node.js project's dependencies and scripts is:
- Which built-in Node.js module is used to read and write files?
…and 97 more.