Node.js Web Module
Node.js Web Module
What is a Web Server?
A Web Server is a software application that processes HTTP requests sent by clients such as web browsers and responds with web content, typically HTML pages, along with resources like images, CSS, and JavaScript files.
Introduction to Applied AI:–Click Here
Web servers often support server-side scripting, allowing them to run scripts that perform tasks like database queries or complex logic before returning results to the client. In some setups, web servers forward these requests to an application server that handles business logic and returns processed data to the client through the web server.
One of the most widely used web servers is Apache, an open-source project that has been a cornerstone of web hosting for decades.
Data Science Tutorial:–Click Here
Web Application Architecture
A typical web application architecture is structured into four key layers:
- Client Layer:
This layer includes web browsers, mobile browsers, or applications that send HTTP requests to the web server. - Server Layer:
The web server resides here. It intercepts incoming client requests and responds with the appropriate content. - Business Layer:
The application server belongs to this layer. It performs processing tasks, interacts with databases or external systems, and prepares the data to be sent back via the web server. - Data Layer:
This layer includes databases or other data sources that store and provide information required by the business layer.
Download New Real Time Projects :–Click here
Node.js Web Layer
Node.js simplifies the creation of web servers with its built-in HTTP module, allowing developers to set up a fully functional server using minimal code.
Below is an example of how to create a simple web server using Node.js:
Machine Learning Tutorial:–Click Here
var http = require('http');
var fs = require('fs');
var url = require('url');
http.createServer(function (request, response) {
var pathname = url.parse(request.url).pathname;
console.log("Request for " + pathname + " received.");
// Serve index.html for root request
if (pathname === "/" || pathname === "/index.html") {
pathname = "/index.html";
}
// Ignore favicon.ico requests
if (pathname === "/favicon.ico") {
response.writeHead(204); // No Content
return response.end();
}
fs.readFile(pathname.substr(1), function (err, data) {
if (err) {
console.log(err);
response.writeHead(404, {'Content-Type': 'text/html'});
response.write("<h1>404 Not Found</h1>");
} else {
response.writeHead(200, {'Content-Type': 'text/html'});
response.write(data.toString());
}
response.end();
});
}).listen(8081);
console.log('Server running at http://127.0.0.1:8081/');
Creating a Sample HTML Page
In the same directory as your server.js
file, create a new file named index.html and add the following content:
Complete Advance AI topics:-Â CLICK HERE
<html>
<head>
<title>Sample Page</title>
</head>
<body>
Hello UpdateGadh!
</body>
</html>
Running the Server
- Open the Node.js command prompt.
- Navigate to the directory containing your
server.js
file. - Run the command:
node server.js
- Open your browser and visit:
http://127.0.0.1:8081/index.html
You should see a web page displaying:
Hello UpdateGadh!
Deep Learning Tutorial:– Click Here
Complete Python Course with Advance topics:-Click Here
SQL Tutorial :–Click Here
node js web module w3schools types of modules in node js node js web module tutorial node js web module example node js web module list node js module local module in node js example http module in node js nodejs module, http module nodejs, nodejs http module, server using http module nodejs, access html file using fs module in nodejs, http module node js, build first nodejs web application server, node js web app, node modules, node js web server, your first node.js web server, nodejs, module, node js web server example, learn nodejs, nodejs, modules, module bundler, how to use node http module, node js web server tutorial, http nodejs, path module, http module, login nodejs, nodejs hindi, nodejs basics, what is nodejs
Post Comment