Q: 8
Refer to the code below:
01 const server = require(‘server’);
02 /* Insert code here */
A developer imports a library that creates a web server. The imported library uses events and
callbacks to start the servers
Which code should be inserted at the line 03 to set up an event and start the web server ?
Options
Discussion
I don't think it's B. C should work since calling server() would start the server directly, especially if the library's main export is a function. The event/callback thing in B seems a bit much for just booting up. Maybe I'm missing something subtle?
C or B? Not totally sure since if the library exports a function, C (server()) sometimes starts it directly. But B fits the event/callback style Node uses. I'd probably pick B unless docs say otherwise.
B here-matches the event and callback pattern Node.js expects for server startup. Practice tests or hands-on coding labs with event emitters make this kind of thing clearer imo. Not 100 percent but feels right.
C tbh, just calling server() should start it right? Not sure if I'm missing something about events here. Can someone confirm?
B for me. That uses server.on with a callback, which is basically how Node event-driven stuff goes. Pretty sure that's the intent.
Looks like B is the best match here. It sets up the event and callback, which is standard in Node.js server patterns.
Pretty sure it's B. The question wants you to use an event with a callback, and that's exactly how server.on() works in Node.js. Saw a similar pattern in some practice questions too, but correct me if I'm missing something.
Hard to say, C-if the server export is a function, calling server() directly often starts it, not always event-based.
B , C is a classic trap here since it ignores the event/callback pattern the question wants. Not 100 percent sure though.
Nah, I think it's B here. The question says you need to set up an event and use a callback, which is what
server.on() does. C looks tempting but skips the event-driven part.Be respectful. No spam.