-
Notifications
You must be signed in to change notification settings - Fork 1
/
myserver_hostname.js
39 lines (32 loc) · 968 Bytes
/
myserver_hostname.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
{
"date_of_creation": "23 August 2017",
"aim_of_source": 'Creating a simple http server',
"coded_by": 'Rishikesh Agrawani',
}
*/
//Including http module
var http = require("http")
//Setting port & ip of localhost
var port = 8080
var hostname = "127.0.0.1"
//HTML text to display on the browser
var htmlText = "<center>"+
"<h1 style='color:green'> Node.js is JavaScript Runtime</h1>"+
"<a href='https://nodejs.org/en/'>Visit here</a> to download"+
"</center>"
//Printing simple log message
console.log("Starting Node server")
//Creating server
server = http.createServer(
function(request, response){
response.writeHead(200, {"Content-Type":"text/html"})
response.end(htmlText)
}
)
//Our http server should listen on port 8080
server.listen(port, hostname, function(){
console.log(`Server is running at http://${hostname}:${port}`)
})
//Printing log messages
console.log("Server started which is listening on port 8080")