-
Notifications
You must be signed in to change notification settings - Fork 1
/
myserver.js
38 lines (31 loc) · 953 Bytes
/
myserver.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
/**
{
"date_of_creation": "23 August 2017",
"aim_of_source": 'Creating a simple http server',
"coded_by": 'Rishikesh Agrawani',
"output_img_link": "images/0001set1myserver2017-08-23at7.23.27 PM.png"
}
*/
//Including http module
var http = require("http")
//Setting port
var port = 8080
//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/'>Click 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)
//Printing log messages
console.log("Server started which is listening on port 8080")
console.log("Visit at http://127.0.0.1:"+port)