cd ../labs
Node.jsintermediateabout 40 minutes
Node.js: modules and async work
Exports and imports, promises, async/await and error handling, with the JavaScript parts running live.
By the end you can
- Split code into modules and import it back
- Read and write promise-based code
- Use async/await without swallowing errors
- Know which work belongs on a server rather than in a browser
Easier if you did first
0 of 3 done
step 1 of 3
Modules and what runs where
Node runs JavaScript outside the browser: on a server, where it can read files, open sockets and hold secrets.
The language is the same; what differs is what is available. There is no document in Node, and no file system in a browser.
The JavaScript in the next step runs in your browser, so Node-only APIs are described here rather than executed.
question 1 of 3
Which pair is the modern (ES module) way to share code?
question 2 of 3
Why must an API key live on the server rather than in front-end code?
question 3 of 3
What does this print, and why?
console.log("one"); setTimeout(() => console.log("two"), 0); Promise.resolve().then(() => console.log("three")); console.log("four");