Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jun 13th, 2012  |  syntax: None  |  size: 0.68 KB  |  hits: 9  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. http.Server doesn't have addListener in node.js? It isn't a event emitter?
  2. var http = require('http');
  3. http.createServer(function (req, res) {
  4.   res.writeHead(200, {'Content-Type': 'text/plain'});
  5.   res.end('Hello Node.jsn');
  6. }).listen(80, "127.0.0.1");
  7. http.Server.addListener('request', function(req,res){
  8.   console.log(req.headers);
  9. });
  10. console.log('Server running at http://127.0.0.1');
  11.        
  12. var http = require('http');
  13. var myServer = http.createServer(function (req, res) {
  14.     res.writeHead(200, {'Content-Type': 'text/plain'});
  15.     res.end('Hello Node.jsn');
  16. });
  17. myServer.listen(80, "127.0.0.1");
  18. myServer.addListener('request', function(req,res){
  19.     console.log(req.headers);
  20. });