Advertisement
Guest User

Untitled

a guest
Jun 25th, 2016
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.61 KB | None | 0 0
  1. var http = require('http');
  2. var fs = require('fs');
  3.  
  4. //404 response
  5.  
  6. function send404response(response){
  7. response.writeHead(404, {"Context-Type": "text/plain"});
  8. response.write("Error 404: Page not found!");
  9. response.end();
  10.  
  11. }
  12.  
  13. function onRequest(request, response){
  14.  
  15. if( request.method == 'GET' && request.url == '/' ){
  16.  
  17. response.writeHead(200, {"Context-Type": "text/html"});
  18. fs.createReadStream("./index.html").pipe(response);
  19.  
  20. }else{
  21.  
  22. send404response(response);
  23.  
  24. }
  25.  
  26.  
  27. }
  28.  
  29. http.createServer(onRequest).listen(8888);
  30. console
  31.  
  32. <!DOCTYPE html>
  33. <html lang="en">
  34. <head>
  35.  
  36. <meta charset="UTF-8">
  37. <link rel="stylesheet" type="text/css" href="main.css" >
  38. <title>First node app</title>
  39. </head>
  40. <body>
  41. <div class="header"></div>
  42. <div class="container">Welcome to my first website! <br> This website is created in NodeJs!</div>
  43. </body>
  44. </html>
  45.  
  46. *{
  47.  
  48. margin: 0px;
  49. padding: 0px;
  50.  
  51. }
  52.  
  53. body{
  54.  
  55. background: url('http://i.stack.imgur.com/1voHP.png') repeat;
  56. font-size: 100%;
  57.  
  58.  
  59. }
  60.  
  61. .header{
  62.  
  63. width: 100%;
  64. height: 500px;
  65. background: rgba(0,0,0,.9);
  66.  
  67. }
  68.  
  69. .container{
  70. font-size: 1em;
  71. margin: 0 auto;
  72.  
  73. width: 70%;
  74.  
  75. height: 90%;
  76.  
  77. background: rgba(0,0,0,.3);
  78. padding: 5%;
  79.  
  80. }*{
  81.  
  82. margin: 0px;
  83. padding: 0px;
  84.  
  85. }
  86.  
  87. body{
  88.  
  89. background: url('http://i.stack.imgur.com/1voHP.png') repeat;
  90. font-size: 100%;
  91.  
  92.  
  93. }
  94.  
  95. .header{
  96.  
  97. width: 100%;
  98. height: 500px;
  99. background: rgba(0,0,0,.9);
  100.  
  101. }
  102.  
  103. .container{
  104. font-size: 1em;
  105. margin: 0 auto;
  106.  
  107. width: 70%;
  108.  
  109. height: 90%;
  110.  
  111. background: rgba(0,0,0,.3);
  112. padding: 5%;
  113.  
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement