Learn Node Js MCQs
Prepare Node Js MCQs (Multiple choice Questions) for exam and job interviews.
What does the `os.homedir()` method return?
1) The home directory of the current user
2) The system’s hostname
3) The system’s architecture
4) The system’s uptime
Answer : Option 1
How do you create a Transform stream in Node.js?
1) Using `stream.Transform` class
2) Using `stream.Readable` class
3) Using `stream.Writable` class
4) Using `stream.Duplex` class
Answer : Option 1
What is the purpose of the `process.exit()` method?
1) To terminate the Node.js process
2) To create a new process
3) To handle errors in a process
4) To restart the Node.js process
Answer : Option 1
How do you set an environment variable in Node.js?
1) By using `process.env`
2) By using `process.nextTick()`
3) By using `process.exit()`
4) By using `process.cwd()`
Answer : Option 1
What does `crypto.randomBytes()` do?
1) Generates cryptographically strong pseudo-random data
2) Encrypts data
3) Decrypts data
4) Hashes data
Answer : Option 1
How do you use the `process.argv` array?
1) To access command-line arguments
2) To get the current working directory
3) To set an environment variable
4) To handle errors in the process
Answer : Option 1
What is the purpose of `stream.finished()`?
1) To detect when a stream has finished or encountered an error
2) To create a readable stream
3) To create a writable stream
4) To create a transform stream
Answer : Option 1
How do you create a Duplex stream in Node.js?
1) Using `stream.Duplex` class
2) Using `stream.Readable` class
3) Using `stream.Writable` class
4) Using `stream.Transform` class
Answer : Option 1
What does the `fs.readdir()` method do?
1) Reads the contents of a directory
2) Reads the contents of a file
3) Writes data to a file
4) Deletes a file
Answer : Option 1
How do you create a Readable stream from a string?
1) Using `stream.Readable.from()`
2) Using `stream.Writable.from()`
3) Using `stream.Transform.from()`
4) Using `stream.Duplex.from()`
Answer : Option 1