Node Connect example

Posted on in JavaScript Node JS

The example below can be easily replaced with Node Connect. Just with a few lines.
app.js

var http = require('http');
var path = require('path');
var fs = require('fs');
var extensions = { 
   ".html" : 'text/html', 
   ".css" : 'text/css', 
   ".js" : 'application/javascript',
   ".json" : 'application/javascript', 
   ".png" : 'images/png', 
   ".gif" : 'images/gif', 
   ".jpg" : 'images/jpeg' 
} 

http.createServer(function(req, res){ 
   var filename = path.basename(req.url) || 'index.html', 
      ext = path.extname(filename), 
      dir = path.dirname(req.url).substring(1), 
      localPath = __dirname + "/views/"; 

     //console.log(localPath); 
     if(extensions[ext]){
        localPath += (dir ? dir + "/" : "") + filename; 
        path.exists(localPath, function(exists){ 
           if(exists){ 
              getFile(localPath, extensions[ext], res) 
           } else { 
              res.writeHead(404); res.end();
           } 
        }); 
     }
}).listen(8000, '127.0.0.1'); 

getFile = function(localPath, mimeType, res){ 
   fs.readFile(localPath, function(err, contents){ 
   if(!err){ 
      res.writeHead(200, { 
         "Content-Type" : mimeType, 
         "Content-Length" : contents.length 
      }); 
      res.end(contents); 
   } else { 
      res.writeHead(500); 
      res.end(); 
   } 
});

Now install Connect:

$ sudo npm install connect

app.js

var connect = require("connect");
connect().use(connect.static(__dirname + "/views")).listen(8000);

cialis pills for sale levitra generic levitra 20 mg cialis vs viagra levitra vs cialis what is cialis viagra from canada how does cialis work cialis daily cheap cialis how long does levitra last cialis 5mg daily pfizer viagra coupons cialis dosage levitra reviews is viagra government funded in america revatio vs viagra how to take cialis viamedic cialis cialis testimonials is viagra funded by government discount cialis viagra vs cialis vs levitra viagra price levitra 20 mg cost walmart cialis cheap cialis vs viagra levitra loc us cialis online canada viagra viagra pill free viagra generic cialis at walmart non prescribed viagra viagra single packs cost viagra best price viagra without prescription buy viagra viagra sex viagra online cialis from canada viagra 100mg price walmart viagra on line no prec inexpensive viagra pills levitra vs viagra buy cialis online viagra pharmacy cialis effects cialis free trial cialis pharmacy prices levitra 20mg cialis medication viagra vs cialis cialis canadian pharmacy cialis price natural viagra viagra prices without insurance levitra prices cialis on line best price viagra viagra coupons from pfizer cialis coupon 20 mg cealis cialis discount cialis coupons 2017 levitra 10mg generic levitra cialis reviews viagra cost cyalis sophia viagra lowest cialis prices levitra cost cialis 20 mg cost of levitra cvs pharmacy viagra coupons buy levitra cialis 10 mg canadian viagra cialis generic online viagra buy viagra online viagra for women cialis patent expiration 2017 cialis 5mg levitra without a doctor prescription viagra cheap viagra what does viagra do levitra vs viagra canadian cialis healthy man viagra is viagra covered by insurance viagra generic cialis 20mg viagra vs cialis vs levitra viagra coupons 75 off cialis 20mg directions cialis patent expiration cialis dosage strengths cialis dosage recommendations viagra side effects cialis or viagra cialis for men discount viagra does the government fund viagra sildenafil vs viagra sex viagra for women levitra viagra on line buy levitra online viagra substitute how much does viagra cost levitra 10 mg cialis coupon print female viagra erectile dysfunction cialis levitra online side effects of viagra viagra coupons side effects of cialis utilisation viagra viagra government funded canada cialis cialis patent expiration date extended herbal viagra women viagra cialis canada buy cialis cialis generic viagra 100mg viagra pills cialis coupons viagra alternatives levitra coupons cialis side effects cialis voucher when will cialis go generic cialis cost viagra vs cialis levitra dosage how much does cialis cost cialis copay card over the counter viagra does viagra work natural viagra alternatives that work otc viagra cialis trial is viagra federally funded trial viagra sample cilias cialis coupons from manufacturer how long does viagra last viagra pills for sale viagra for sale cialis without a doctor's prescription cialis sample generic cialis cialis samples online cialis what is viagra cialis tadalafil viagra samples viagra costs daily cialis generic viagra levitra canada levitra coupon viagra canada cialis website order online viagra cialis 30 day trial coupon viagra ingredients where to buy viagra viagra from amazon viagra government funding levitra vs viagra for hardness liquid cialis what is levitra free cialis cialis or viagra cialis coupons printable cialis 30 day sample cialis professional viagra dose cialis pricing cost of cialis cialis coupon pfizer viagra viagra dosage viagra single packs viagra activate cialis savings card generic cialis tadalafil viagra porn viagra prices cialis generic tadalafil cost of viagra cialis for women how does viagra work levitra side effects generic for cialis 9 levitra at walmart cialis alternative cialis 5 mg walgreens viagra substitute viagra patent expiration viagra savings offer viagra cialis viagra 100mg tablets retail price female viagra pills viagra coupon cialis otc cialis pills stendra vs viagra viagra without a doctor prescription usa 200 cialis coupon wholesale cialis viagra girls is viagra government funded price cialis cialis generic availability viagra without a doctor prescription cialis prices cialis samples overnight generic viagra available in usa generic for viagra cialas cialis for daily use cialis for sale cialis for bph

Post a Comment

Your email is never published nor shared.
Required fields are marked *