1. Which Node.js module can be used to get the IP address of the server the program is running on?
Answers:
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:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
npm view <package-name> version
Answers:
Answers:
Answers:
Answers:
Answers:
Answers:
- util
- os
- dns
- net
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.
- It creates an HTTP GET request, and synchronously pipes its response into a writeable file stream.
- It creates an HTTP POST request and pipes its response into a readable file stream.
- It creates an HTTP POST request and pipes its response into a writeable file stream.
Answers:
- fs.write()
- fs.writeFile()
- fs.createWriteStream()
- fs.writeStream()
Answers:
- process.stdout.print()
- console.error()
- console.log()
- process.stdout.write()
Answers:
- It is a local object.
- It is an instance of the events.EventEmitter class.
- The process.exit(1) method ends the process with a “success” code.
- “process.stderr” and “process.stdout” are non-blocking if they refer to regular files or TTY file descriptors.
Answers:
- fs.exists()
- fs.existsSync()
- fs.checkFileSync()
- fs.checkDirSync()
Answers:
- fs.readdir()
- fs.readdirSync()
- fs.readDirectory()
- fs.readdirAsync()
Answers:
- npm upgrade -g
- npm install -uga
- npm update -g
- npm version –install-latest
Answers:
- It is not possible to stream data through a child process’ stdin, stdout, and stderr in a fully non-blocking way.
- Child processes always have two streams associated with them.
- “require(‘child_process’).spawn()” can be used to create a child process.
- “require(‘child_process’).fork()” can be used to create a child process.
Answers:
- process.argv
- args.argv
- arguments.argv
- env.argv
Answers:
- var fs = require(‘fs’); fs.createReadStream(‘test.file’).pipe(fs.createWriteStream(‘newFile.file’));
- var fs = require(‘fs’); fs.createReadBuffer(‘test.file’).pipe(fs.createWriteBuffer(‘newFile.file’));
- var fs = require(‘file’); fs.createFileReader(‘test.file’).pipe(fs.createFileWriter(‘newFile.file’));
- var fs = require(‘fs’); fs.createReadBuffer(‘test.file’).stream(fs.createWriteBuffer(‘newFile.file’));
Answers:
- It is the object that gets returned from a require() call.
- It can be assigned in a callback.
- Assigning an export object to module.exports will rebind the local exports variable.
- None of these.
Answers:
- fs.readFileStream()
- fs.readFile()
- fs.createReadStream()
- fs.createFileStream()
Answers:
- npm install
- npm install –dev
- npm install –production
- None of these
Answers:
- “console.log” can take only a single argument.
- “console.log” prints to stdout without a newline.
- Its functions are synchronous when the destination is a terminal or a file, and and asynchronous when it’s a pipe.
- Its functions are asynchronous when the destination is a terminal or a file, and and synchronous when it’s a pipe.
npm view <package-name> version
Answers:
- It shows the version of the package installed globally.
- It shows the version of the package installed locally.
- It shows the version of the package that is cached.
- It shows the latest version of the package that is available.
Answers:
- __filename
- os.tmpdir()
- path.dirname()
- path.basename()
Answers:
- process.env.ENV_VARIABLE
- process.argv.ENV_VARIABLE
- process.env.var.ENV_VARIABLE
- process.environment.ENV_VARIABLE
Answers:
- node
- The file path of the JavaScript file.
- The first command line argument.
- The second command line argument.
Answers:
- -g
- –global
- -l
- –link
No comments:
Post a Comment