Chapter1 - Introduction To Node - Js
Chapter1 - Introduction To Node - Js
ELECTIVE 3: Chapter 1 – 4
Vast Ecosystem: Rich package ecosystem via npm (Node Package Manager).
Key Concepts:
Use Cases: Real-time applications like chat apps, live feeds, or streaming services.
Incoming request
Setting Up Node.js
Folder Structure: Organize your project into clear folders (e.g., /src, /routes).
Create app.js:
• console.log("Hello, Node.js!");
node app.js
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
Instead of overwriting, you can add data to the end of an existing file.
Deleting Files
Creating 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).
REVIEWER
ELECTIVE 3: Chapter 1 – 4
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.
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.