Hi!
first of all: help for nodeschool workshoper can be found here
https://github.com/nodeschool/discussions/issues
secondly: your filename is wrong, as forest said, there is no trailing
slash on __dirname. either you add it mnanually or use path.join()
thirdly: you can't do res.end(err). res.end() uses re.write() and write
expects a Buffer or a string. so if you want to present the error message
to the client you have to call res.end('"ERROR:" + err.message) or
something like that.
Am Sonntag, 11. Januar 2015 17:06:22 UTC+1 schrieb Roelof Wobben:
>
> 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/e9d450a0-c538-489a-bd73-18b1be393a8c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.