1. Which Node.js module can be used to get the IP address of the server the
program is running on?
Answers: • os
2. What does the following code do?
var http = require('http');
var fs = require('fs');
var file = fs.createWriteStream("file.png");
var request = http.get("http://path/to/file.png", function(response) {
response.pipe(file);
});
Answers: • It creates an HTTP GET request and pipes its response into a writeable file stream.
3. Which of the following methods can be used to write a file in Node.js?
Answers: • fs.writeFile()
4. Which of the following methods will print to the console without a trailing new line?
Answers: • process.stdout.write()
5. Which of the following statements is true about the process object in Node.js?
Answers: • It is an instance of the events.EventEmitter class.
6. Which of the following will synchronously check if a file/directory exists?
Answers: • fs.existsSync()
7. Which of the following methods can be used to read the contents of a directory?
Answers: • fs.readdir()
8. Which of the following console commands will update all installed global packages to the latest available versions?
Answers: • npm update -g
9. Which of the following statements are true about the child_process module in Node.js?
Answers: • "require('child_process').fork()" can be used to create a child process.
10. Which array contains the command line arguments in Node.js?
Answers: • process.argv
11. Which of the following will copy a file in Node.js?
Answers: • var fs = require('fs'); fs.createReadStream('test.file').pipe(fs.createWriteStream('newFile.file'));
12. Which of the following statements are true about the module.exports object in Node.js?
Answers: • It is the object that gets returned from a require() call.
13. Which of the following will open a file, then read its contents one line at a time?
Answers: • fs.createReadStream()
14. Which of the following NPM commands will install both dependencies and devDependencies of a given project?
Answers: npm install
15. Which of the following statements is true about the console Object in Node.js?
Answers: • Its functions are synchronous when the destination is a terminal or a file, and and asynchronous when it's a pipe.
16. What does the following command do?
npm view <package-name> version
Answers: • It shows the latest version of the package that is available.
17. Which of the following can be used to get the currently running script's path in Node.js?
Answers: • __filename
18. Which of the following can be used to access the environment variable, "ENV_VARIABLE" in Node.js?
Answers: • process.env.ENV_VARIABLE
19. What does process.argv[1] contain?
Answers: • The file path of the JavaScript file.
20. Which of the following command-line arguments to "npm install" will allow an NPM package's binaries to be run outside the project folder?
Answers: • -g
Answers: • os
2. What does the following code do?
var http = require('http');
var fs = require('fs');
var file = fs.createWriteStream("file.png");
var request = http.get("http://path/to/file.png", function(response) {
response.pipe(file);
});
Answers: • It creates an HTTP GET request and pipes its response into a writeable file stream.
3. Which of the following methods can be used to write a file in Node.js?
Answers: • fs.writeFile()
4. Which of the following methods will print to the console without a trailing new line?
Answers: • process.stdout.write()
5. Which of the following statements is true about the process object in Node.js?
Answers: • It is an instance of the events.EventEmitter class.
6. Which of the following will synchronously check if a file/directory exists?
Answers: • fs.existsSync()
7. Which of the following methods can be used to read the contents of a directory?
Answers: • fs.readdir()
8. Which of the following console commands will update all installed global packages to the latest available versions?
Answers: • npm update -g
9. Which of the following statements are true about the child_process module in Node.js?
Answers: • "require('child_process').fork()" can be used to create a child process.
10. Which array contains the command line arguments in Node.js?
Answers: • process.argv
11. Which of the following will copy a file in Node.js?
Answers: • var fs = require('fs'); fs.createReadStream('test.file').pipe(fs.createWriteStream('newFile.file'));
12. Which of the following statements are true about the module.exports object in Node.js?
Answers: • It is the object that gets returned from a require() call.
13. Which of the following will open a file, then read its contents one line at a time?
Answers: • fs.createReadStream()
14. Which of the following NPM commands will install both dependencies and devDependencies of a given project?
Answers: npm install
15. Which of the following statements is true about the console Object in Node.js?
Answers: • Its functions are synchronous when the destination is a terminal or a file, and and asynchronous when it's a pipe.
16. What does the following command do?
npm view <package-name> version
Answers: • It shows the latest version of the package that is available.
17. Which of the following can be used to get the currently running script's path in Node.js?
Answers: • __filename
18. Which of the following can be used to access the environment variable, "ENV_VARIABLE" in Node.js?
Answers: • process.env.ENV_VARIABLE
19. What does process.argv[1] contain?
Answers: • The file path of the JavaScript file.
20. Which of the following command-line arguments to "npm install" will allow an NPM package's binaries to be run outside the project folder?
Answers: • -g
No comments:
Post a Comment