I use learnyounode run command. and after these tips the problem is solved. 

it seems that __dirname does not the work properly.

Roelof


Op zondag 11 januari 2015 19:55:19 UTC+1 schreef Forrest L Norvell:

> What command line are you using? What happens when you add console.log 
> statements saying what values you’re going to pass to each of the library 
> calls you make?
>
> (You should use path.resolve or path.join instead of filename = __dirname 
> + argv[3] — __dirname doesn’t come with a trailing slash, among other 
> things.)
>
> F
> ​
>
> On Sun, Jan 11, 2015 at 8:06 AM, Roelof Wobben <[email protected] 
> <javascript:>> wrote:
>
>> 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] <javascript:>.
>> To post to this group, send email to [email protected] 
>> <javascript:>.
>> To view this discussion on the web visit 
>> https://groups.google.com/d/msgid/nodejs/7a0d1159-c805-4d6a-9605-25a6d3bc9ff9%40googlegroups.com
>>  
>> <https://groups.google.com/d/msgid/nodejs/7a0d1159-c805-4d6a-9605-25a6d3bc9ff9%40googlegroups.com?utm_medium=email&utm_source=footer>
>> .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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/48d05c92-7b8c-45f2-aab9-9e033032bfa9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to