Advertisement
Guest User

Untitled

a guest
Nov 28th, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. var http = require("http"),
  2. fs = require('fs'),
  3. async = require('./js/async.js');
  4.  
  5. var onRequest = function(request,response) {
  6. response.writeHead(200,{ "Content-Type": "text/html; charset=utf-8" });
  7.  
  8. var file; // 'file' declared
  9.  
  10. var main = function(callback) {
  11. fs.readFile('.\html\admin.html','utf-8',function(err,data) {
  12. file = data; // 'file' is given content of admin.html
  13. console.log('2 >> ' + typeof file);
  14. });
  15. callback(null);
  16. }
  17.  
  18. console.log('1 >> ' + typeof file);
  19.  
  20. async.series([
  21. main
  22. ], function() { // At this point 'file' is still undefined, that's odd
  23. response.end(); // 'cause it's a callback and should be fired after 'main'
  24. console.log('3 >> ' + typeof file);
  25. });
  26. }
  27.  
  28. http.createServer(onRequest).listen(80);
  29.  
  30. 1 >> undefined
  31. 3 >> undefined
  32. 2 >> string
  33.  
  34. 1 >> undefined
  35. 2 >> string
  36. 3 >> string
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement