Welcome! Here you can paste sources and general debugging text, You can even set yourself a password if you want to keep it just for yourself.

Posted by nodejs on February Sun 23rd 6:06 PM - Never Expires - Views: 469

  1. var http = require('http');
  2. //var url = require('url');
  3. var fs = require('fs');
  4.  
  5. var server = http.createServer(function(request, response){
  6.  
  7.   response.writeHead(200, {"Content-Type": "text/html"});
  8.  
  9.   if(request.url == "/"){
  10.         fs.readFile(__dirname + '/index.html', function(err, html){            
  11.             //response.writeHeader(200, {'Content-Type': 'text/html'});
  12.             response.write(html);
  13.            // response.end();          
  14.         });
  15.   }else if(request.url == "/bemvindo"){
  16.     fs.readFile(__dirname + '/bemvindo.html', function(err, html){             
  17.             //response.writeHeader(200, {'Content-Type': 'text/html'});
  18.             response.write(html);
  19.            // response.end();          
  20.         });
  21.   }else{
  22.     response.write("<html><body><h1>Página não encontrada!</h1>");
  23.     response.write("<a href='/'>Voltar para o início</a>");
  24.     response.write("</body></html>");
  25.   }
  26.  
  27.   response.end();
  28.  
  29. });
  30.  
  31. server.listen(3000, function(){
  32.   console.log('Executando Servidor HTTP');
  33. });
Language:
To highlight particular lines, prefix each line with @@




© 2017  admin@YSblue (Implemented and Adapted) - Powered by PASTE 1.0