web_applications_nodejs_express
web_applications_nodejs_express
- Frontend: Client-side of web applications that users interact with, typically built using HTML, CSS,
- Backend: Server-side that processes data and manages databases, typically built using Node.js,
What is HTTP?
HTTP (Hypertext Transfer Protocol) is the protocol used to transfer data over the web. It is the
foundation for data communication between clients (browsers) and servers. HTTP operates as a
request-response protocol.
A URL (Uniform Resource Locator) is the address used to identify resources on the web. It tells the
browser where to send HTTP requests and is used to retrieve resources such as HTML pages,
(username=mountblue).
Commonly Used HTTP Request Methods
- Request Body: Sent in the body for POST/PUT requests (usually in JSON or form data format).
The default status code is usually 200 OK for a successful response unless otherwise specified.
The Content-Length header indicates the size (in bytes) of the response body. It helps the client
know how much data to expect.
- Path: Refers to the entire string following the domain, including the query string.
- Pathname: Only the path to the resource, excluding the query string (e.g., /users/profile).
What is Node.js?
Node.js is a runtime environment that allows you to run JavaScript on the server. It uses an
event-driven, non-blocking I/O model, making it ideal for building scalable applications.
Node.js uses an event loop and callback mechanism. When an I/O operation (like reading a file) is
initiated, it doesn't block the execution. Instead, it registers a callback, continues executing other
res.write('Hello, World!');
res.end();
});
NPM (Node Package Manager) is a tool for managing JavaScript packages and dependencies in
package.json contains metadata about the project, including dependencies, scripts, and version
What is Express?
Express is a minimal and flexible Node.js web application framework that provides tools to build web
the server).
"scripts": {
Middlewares are functions that execute during the request-response cycle. They can modify the
The next() function passes control to the next middleware in the stack. Without it, the request would
hang.
app.use(express.static('public'));
express.json() Middleware
This middleware parses incoming JSON request payloads, making it accessible via req.body.
Error Handler Middleware in Express
Error-handling middleware has four arguments (err, req, res, next) and is used to handle errors. It's
different from other middlewares because it specifically catches errors during request processing.
});