How To Create Server With Nodejs
How To Create Server With Nodejs
server in Nodejs
PW SKILLS
Content
1. HTTP module
2. Feature of HTTP module
3. Server with HTTP module
PW SKILLS
HTTP modules
● Hypertext Transport Protocol modules of Nodejs
● HTTP modules is the core modules of Nodejs
● HTTP modules provide way to create server and handle HTTP request and response.
● It exposes various classes, functions and properties to work with HTTP
● To use the HTTP server and Client one must require(“node:http”)
PW SKILLS
Features of HTTP method
● Create an HTTP server using `http.createServer()`
● Listen to incoming request using the `server.listen()` method
● Handle incoming requests and send responses using the `request` and `response` object passed to the server’s
request event
● Set headers on the response object using `response.setHeader()`
● Write data to the response object using `response.write()`
● End the response using `response.end()`
● Send an HTTP request to a server using `http.request()`
● Receive a response from a server using the `response` event of the `http.clientRequest` object returned by
`http.request()`
PW SKILLS
Server with HTTP module
const http = require("node:http"); // getting the http module
PW SKILLS
THANK
YOU
PW SKILLS