Level 2 exam — harder

Exam — fresh questions

2.1 · Recall

1. What is a Node native module?

fs, path, os, http… ship with Node: require('fs') is enough, zero installation.
2.1 · Application

2. Salim reads reports on a server used by the whole team. Which fs version?

On a server, always async: Sync blocks the event loop for every client.
2.1 · Arbitration

3. A colleague builds paths with __dirname + '/data/' + name. Salim's verdict?

path.join picks the right separator for the system and handles edge cases — never concatenate.
2.2 · Recall

4. What do .on() and .emit() do on an EventEmitter?

.on registers the reaction, .emit triggers it with data — decoupled by name.
2.2 · Application

5. Salim creates an emitter for his import progress. What does he add first?

error is special: emitted with no listener, it crashes the program — always listen for it.
2.2 · Application

6. The team wants three independent reactions to each imported file (display, log, counter). How?

Adding behaviour = adding a listener; the emitter stays unchanged.
2.3 · Recall

7. What is the principle of a stream?

In chunks, as it flows: constant memory whatever the total size.
2.3 · Application

8. Salim copies a 2 GB export. Which line does the job without saturating RAM?

.pipe() flows chunks from reading to writing, with flow control.
2.3 · Arbitration

9. A colleague wants to load everything into memory “because RAM will cope”. Verdict?

Large volumes = streams (constant memory); readFile stays perfect for small files.
2.4 · Application

10. Salim creates his first native server. Which two lines are the foundation?

createServer receives (req, res) on each request; listen opens the listening port.
2.4 · Application

11. The GET /rapports route must return the inventory as JSON. What does Salim do?

The right status + the right Content-Type + the serialised body, finished with end().
2.4 · Arbitration

12. Should you skip the native server to go straight to Express?

Express rests on http: the native server shows what it simplifies and helps debugging.
What's next?
Back to the guideGuide contents