Node.js Тест Upwork

Which of the following code converts a buffer buf to JSON object?

buf.toJSON()
buf.json()
buf.covertToJson()
buf.jsonify()

Which of the following provides in-built events?

handler
events
callback
throw

Which of the following is true about Node.JS?

Node.js is a JavaScript based framework/platform built on Google Chrome's JavaScript V8 Engine.
Node.JS is used to delevop I/O intensive web applications like video streaming sites, single page applications and other web application.
Node.js is open source and is completely free to use.
All of the above

How to fire event using EventEmitter:

var events = new events.EventEmitter();
events.fireEvent(‘eventName');
events.send('eventName');
events.fire('eventName');
 events.emit('eventName');

Which of the following modules is required to create server for NodeJS?

http
server
https

How can the output of one stream be provided as input to another stream?

stream1.pipe(stream2);
stream1.chain(stream2);
stream1.set(stream2);
stream1.createStream(stream2);

REPL stands for

Read Evaluate Print Loop
Read Eval Process Loop
Read Eval Print Loop
None of the above

What is the syntax to list all commands in REPL?

help
.help
??help
None of the above

What is Callback?

Callback is an asynchronous equivalent for a function.
Callback is a technique in which a method call back the caller method.
Both of the above.
None of the above.

Which of the following is correct way to imports http module?

require('http')
import http;
include http;
module http;

Which are the below NodeJS features?
Note: There may be more than one right answer.

Very Fast
No Buffering
Single Threaded but Highly Scalable
Asynchronous and Event Driven
None of above

Which of the following code print the total free memory of operating system?

console.log('free memory : ' + os.freemem() + " bytes.");
console.log('free memory : ' + os.freemem + " bytes.");
console.log('free memory : ' + os.getFreeMemory() + " bytes.");
None of the above.

Which of the following timers methods exists in Node.js?
Note: There may be more than one right answer.

setSleep
clearTimout
sleep
setTimeout

Which of the following code can make a request to a web server?

http.request(options, callback)
http.createRequest(options, callback)
http.makeRequest(options, callback)
None of the above.

Select valid stream instances:
Note: There may be more than one right answer.

stream.Transform
stream.Duplex
stream.Write
stream.Read
All are valid

What does the following line of code do?
var http = require("http");

Uses the require directive to load the http module
Stores the returned HTTP instance into an http variable
Both of the above
None of the above

Which method of fs module is used to truncate a file?

fs.delete(fd, len, callback)
fs.remove(fd, len, callback)
fs.ftruncate(fd, len, callback)
None of the above.

Which function will delete a file?

fs.unlink(path,callback);
fs.remove(path,callback);
fs.delete(path,callback);
fs.rm(path,callback);

What output will this code produce in the console?
const EventEmitter = require('events');
const myEmit = new EventEmitter();
myEmit.on('slick', () => {});
myEmit.on('key', () => {});
const symbol = Symbol('init');
myEmit.on(symbol, () => {});
console.log(myEmit.eventNames());

[ 'slick', 'key', (init) ]
[ 'slick', 'key', Symbol ]
{ 'slick', 'key', init }
[ 'slick', 'key', Symbol(init) ]
[Symbol(init) ]

Which of the following is true about writable stream?

writable stream is used for write operation.
Output of readable stream can be input to a writable stream.
Both of the above.
None of the above.

Which of the following is the correct way to get a normalized path?

path.normalize('/test/test1//2slashes/1slash/tab/..')
fs.normalize('/test/test1//2slashes/1slash/tab/..')
os.normalize('/test/test1//2slashes/1slash/tab/..')
None of the above.

How to add a listener to event emitter?

eventEmitter.on(‘event',connectHandler);
eventEmitter.at(‘ev',connectHandler);
eventEmitter.receive(‘eventHandler’,connectHandler);
eventEmitter.bind(‘e',connectHandler);

Which code will return total system memory in bytes? os is included like this:

const os = require('os');
os.totalmem()
os.totalmem
os.getTotalMemory()
None of the above

How to Terminate Node REPL using the following short key?

ctrl + c
ctrl + c twice
ctrl + d

Which of the following method resolves an ip address to an array of hostnames?

dns.reverse(ip, callback)
dns.resolve(hostname[, rrtype], callback)
dns.resolve4(hostname, callback)
None of the above.

Which of the following code gets length of a buffer buf?

buf.length
buf.size
buf.length()
buf.size()

How to convert from Buffer instance to string of base64?

Base64.encode(myBuffer);
myBuffer.encode(“base64”);
encode(myBuffer,”base64”);
myBuffer.toString(“base64”);

Consider the following javascript code.
console.log("first");
setTimeout(function() {
    console.log("second");
}, 0);
console.log("third");
What will be the output?

first
third
second

first
second
third

first
second
second
third

None of the above

What is the output in console of this code?
var events = require('events');

var myEventEmitter = new events.EventEmitter();
myEventEmitter.once('a', function () { console.log('a')});
myEventEmitter.on('b', function () { console.log('b')});
myEventEmitter.emit('a');
myEventEmitter.emit('b');
myEventEmitter.emit('a');
myEventEmitter.emit('b');

a
b
a
b

a
b
b

a
b
a

b
a
b
a

Node.js Тест Upwork 2019{jcomments off}