Top built in modules Flashcards
What are the top 5 built in modules commonly used in node projects?
- fs
- path
- os
- events
- http
Explain the role of the fs module and name some functions of it.
Provides a set of methods to interact with the file system.
readFile()
writeFile()
appendFile()
unlink()
readdir()
mkdir()
rmdir()
Explain the role of the path module and name some functions of it.
Provides utilities for joining, resolving, parsing, formatting, normalizing and manipulating paths.
join()
parse()
resolve()
extname()
dirname()
Explain the role of the os module and name some functions of it.
Provides a set of methods for interacting with the operating system.
type()
userInfo()
totalmem()
freemem()
Explain the role of the events module. Explain how to handle events in Node?
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.
What are Event Arguments?
When we emit an event we can pass additional information in the form of parameters/arguments.
myEmitter.emit(“event”, “argument1”, “argument2”);
What is the difference between a function and an event?
Events represent an action and functions performr a specific task.
Events will call functions internally.
What is the role of the http module in Node?
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.
What is the role of the createServer() method in the http module?
Creates an HTTP server.