0% found this document useful (0 votes)
4 views

Chapter 2 - Basic Node - Js Programming

Uploaded by

Jaysie Olimpiada
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views

Chapter 2 - Basic Node - Js Programming

Uploaded by

Jaysie Olimpiada
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Chapter 2: Basic Node.

js Programming

Subtopic

➢ Node.js core modules (fs, path, http)

➢ Writing basic Node.js applications

➢ Understanding the Node.js runtime environment

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

➢ You can read the content of a file.

Writing Files

➢ You can create or overwrite files with the writeFile() method.

Appending Data

➢ Instead of overwriting, you can add data to the end of an existing file.

Deleting Files

➢ You can delete files using the unlink() method.

Creating Directories

➢ You can create directories using the mkdir() method.

Reading Directories

➢ You can read directories using the readdir() method.

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.

You might also like