title: How execute a javascript in a node.js server
body: <p>I have written a node.js server.<br/>
  I am able to extract the HTTP POST and GET variable from the request.<br/>
  I would like to pass those variable to the js script on the server to be executed.<br/>
  In PHP to execute a script I would just point to it @ www.example.com/path/file.php?variable=value<br/></p>
  
  <pre><code>&lt;?php echo "You have ".$_GET['variable'];?&gt;
  </code></pre>
  
  <p>I want to achieve the same with noge.js @ www.example.com/path/file.njs?variable=value<br/>
  My problem is the file.njs is executed as a text.
  I am not using express, a solution without it would be appreciated.</p>
  
  <pre><code> var sys=require("sys"),
   http=require("http"),
   path=require("path"),
   url=require("url"),
   filesys=require("fs"),
   mime=require("./node_modules/mime"),
   head=require("./node_modules/headers/initreq.njs");//this is used to extract the header
   http.createServer(handler).listen(80);//handler function is below
   sys.puts("Node Server Running on 80");
  
   function handler(request,response){
      var myPath=url.parse(request.url).pathname;//get the url
      var ext=myPath.replace(/(.)*\./,'');//get the extension
      var fullPath=path.join(process.cwd(),myPath);//get the working dir &amp; join it with current working dir
      var mimeResult=mime.lookup(fullPath),acceptExt=['html','njs'];  
  
      if(acceptExt.indexOf(ext)!=-1){//only search HTTP header for html|njs files
          head.init(request,response,setContent);//head will correctly contain the $_GET AND $_POST variable
      } else {setContent();}  
  
      function setContent(){
          path.exists(fullPath,function(exists){
              if(!exists){
                  response.writeHeader(404, {"Content-Type":"text/plain"});
                  response.write("404 Not Found:: "+fullPath+"\n");
                  response.end();
              }else{
                  filesys.readFile(fullPath,"binary",function(err,file){
                      if(err){
                          response.writeHeader(500,{"Content-Type":"text/plain"});
                          response.write(err+"::"+myPath+"\n");
                          response.end();
                      }else{                      
                          response.setHeader("Content-Type", mimeResult);
                          response.writeHeader(200);
                          response.write(file,"binary");//this is the file that i want to execute and pass the $_POST &amp; $_GET variable
                          response.end();
                      }
                  });
              }
          });
      }
     sys.puts("Requested:: "+myPath.replace(/(.)*\//,'')+" - "+mimeResult );   
   }
  </code></pre>