Node.js Exercises
Fill in the blanks to test your knowledge.
1
Import the fs module using require
const fs = ("fs");
2
Export a function using module.exports
.exports = function greet() {};
3
Read a file asynchronously
fs.("file.txt", "utf8", (err, data) => {});
4
Create an HTTP server
const server = http.(( req, res) => {
res.end("Hello");
});
5
Listen on a specific port
server.(3000, () => console.log("Running"));
6
Join path segments with path.join
const fullPath = path.(__dirname, "src", "index.js");
7
Emit a custom event on an EventEmitter
emitter.("data", { value: 42 });
8
Listen for a custom event on an EventEmitter
emitter.("data", (payload) => console.log(payload));