I try to make a exercise of nodeschool.io  but I cannot make it work. 

I have this : 


var http = require ('http');
var fs = require('fs')

http.createServer(function(req, res) {

  var filename = __dirname+ process.argv[3]
  var readStream = fs.createReadStream(filename);

  readStream.on('open', function () {
     readStream.pipe(res);
  });

  readStream.on('error', function(err) {
    res.end(err);
  });
}).listen(process.argv[2]);


then I see this error 


http.js:851
    throw new TypeError('first argument must be a string or Buffer');
          ^
TypeError: first argument must be a string or Buffer
    at ServerResponse.OutgoingMessage.write (http.js:851:11)
    at ServerResponse.OutgoingMessage.end (http.js:985:16)
    at ReadStream.<anonymous> 
(/home/roelof/node_exercises/learnyounode/httpfileserver.js:16:9)
    at ReadStream.emit (events.js:95:17)
    at fs.js:1513:12
    at Object.oncomplete (fs.js:107:15)
✗ Error connecting to http://localhost:40856: socket hang up


when I swap the process.argv then I see this message ; 


events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: listen EADDRINUSE
    at errnoException (net.js:904:11)
    at Server._listen2 (net.js:1023:19)
    at listen (net.js:1064:10)
    at Server.listen (net.js:1132:5)
    at Object.<anonymous> 
(/home/roelof/node_exercises/learnyounode/httpfileserver.js:16:4)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
✗ Error connecting to http://localhost:5727: connect ECONNREFUSED


-- 
Job board: http://jobs.nodejs.org/
New group rules: 
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: 
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/7a0d1159-c805-4d6a-9605-25a6d3bc9ff9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to