Top built in modules Flashcards

1
Q

What are the top 5 built in modules commonly used in node projects?

A
  1. fs
  2. path
  3. os
  4. events
  5. http
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Explain the role of the fs module and name some functions of it.

A

Provides a set of methods to interact with the file system.

readFile()
writeFile()
appendFile()
unlink()
readdir()
mkdir()
rmdir()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Explain the role of the path module and name some functions of it.

A

Provides utilities for joining, resolving, parsing, formatting, normalizing and manipulating paths.

join()
parse()
resolve()
extname()
dirname()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Explain the role of the os module and name some functions of it.

A

Provides a set of methods for interacting with the operating system.

type()
userInfo()
totalmem()
freemem()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Explain the role of the events module. Explain how to handle events in Node?

A

Used to handle events.

EventEmitter class of events module is used to register listeners and emit events.

Event listener is a function that will be executed when a particular event occurs.

on() method is used to register event listeners.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What are Event Arguments?

A

When we emit an event we can pass additional information in the form of parameters/arguments.

myEmitter.emit(“event”, “argument1”, “argument2”);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between a function and an event?

A

Events represent an action and functions performr a specific task.

Events will call functions internally.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is the role of the http module in Node?

A

HTTP server for processing HTTP requests and responses.

The http module creates a server that listens on a port for requests and gives responses back to the client.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the role of the createServer() method in the http module?

A

Creates an HTTP server.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly