http.createServer([options][,
requestListener])
This
method returns a new instance of http.Server.
Below
table summarizes the arguments of createServer method.
Argument
|
Type
|
Description
|
|||||||||
options
|
Object
|
Below
table summarizes different options supported by this method.
|
|||||||||
requestListener
|
Function
|
This
function is called on every request.
|
Find
the below working application.
var http = require('http'); var server = http.createServer((request, response) => { response.writeHead(200, { 'Content-Type': 'text/html' }); var dataToWrite = '<html><head><title>Hello World</title></head><body>' + '<h1>Hello World, Welcome to node.js programming</h1>' + '</body></html>'; response.end(dataToWrite); }); server.listen(9000); console.log('Server started and listening on port 9000');
Open
browser and hit the url ‘http://localhost:9000/’, you can see below kind of
screen.
No comments:
Post a Comment