Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
What is the purpose of the `fs.unlinkSync()` method?
1) To delete a file synchronously
2) To rename a file
3) To copy a file
4) To move a file
Answer : Option 1
Which Node.js module is used for zlib compression?
1) zlib
2) http
3) fs
4) path
Answer : Option 1
How do you create a new directory asynchronously in Node.js?
1) Using `fs.mkdir()`
2) Using `fs.mkdirSync()`
3) Using `fs.writeFile()`
4) Using `fs.open()`
Answer : Option 1
What does `path.dirname()` return?
1) The directory name of a path
2) The base name of a path
3) The extension of a path
4) The full path
Answer : Option 1
What does the `assert.strictEqual()` method do?
1) Asserts that two values are strictly equal
2) Asserts that two values are loosely equal
3) Asserts that a value is true
4) Asserts that a value is false
Answer : Option 1
How do you create a custom event emitter in Node.js?
1) By extending the `EventEmitter` class
2) By using the `events` module directly
3) By using the `util` module
4) By using the `stream` module
Answer : Option 1
What is the purpose of `Buffer.from()`?
1) To create a buffer from various inputs
2) To allocate a new buffer of a specified size
3) To compare two buffers
4) To concatenate multiple buffers
Answer : Option 1
How do you set a timeout in Node.js?
1) Using `setTimeout()`
2) Using `clearTimeout()`
3) Using `setInterval()`
4) Using `process.nextTick()`
Answer : Option 1
What does the `http.METHODS` array contain?
1) A list of HTTP request methods supported by Node.js
2) A list of HTTP status codes
3) A list of HTTP header fields
4) A list of HTTP response codes
Answer : Option 1
How do you create a writable stream in Node.js?
1) Using `stream.Writable` class
2) Using `stream.Readable` class
3) Using `stream.Transform` class
4) Using `fs.createWriteStream()`
Answer : Option 4