Chapter 2 - Basic Node - Js Programming
Chapter 2 - Basic Node - Js Programming
js Programming
Subtopic
fs (File System)
➢ Provides functions to work with the file system, enabling you to interact with files and
directories—such as reading, writing, creating, and deleting files. It’s one of the core
modules, so you don’t need to install anything extra to use it.
Reading Files
Writing Files
Appending Data
➢ Instead of overwriting, you can add data to the end of an existing file.
Deleting Files
Creating Directories
Reading Directories
path
➢ Provides utilities for working with file and directory paths. It helps in handling and
manipulating file paths in a platform-independent way, which means it works the same on
both Windows and Unix-like systems (like macOS and Linux).
path.join()
➢ This method joins different parts of a file path into one complete path. It makes sure to use
the correct path separator (/ for Unix, \ for Windows).
path.basename()
➢ This method returns the last part of a file path, typically the file name.
path.dirname()
➢ This returns the directory part of a file path (everything except the file name).
path.extname()
➢ This method extracts the file extension from the file name.
http
➢ Provides the ability to create servers that can respond to client requests using the HTTP
protocol. This protocol is the foundation of data communication on the web, allowing
browsers to request data from servers and receive responses like web pages or other
resources.
http.createServer()
➢ The server listens for incoming requests and responds with data. When a client (such as a
web browser) sends an HTTP request, the server processes it and sends back a response.