Closed amahfouz closed 8 years ago
@amahfouz The validation script makes a get
request to the /home
path, not /
:
Create an Express.js app that runs on localhost:3000, and outputs "Hello World!" when somebody goes to '/home'.
Make the change and see if that works.
Thanks!
I made the change (which was an obvious mistake on my part):
var express = require('express')
var app = express()
app.get('/home', function(req, res) {
res.write('Hello World!')
res.end()
})
app.listen(process.argv[2])
but I still get the same error. The browser still does show the right thing when I hardcode the port and go to http://localhost:3000/home
I dug further and found the solution.js
for the problem which looked like this:
var PassThrough = require('stream').PassThrough || require('readable-stream/passthrough')
module.exports = function(isRun) {
var submissionOut = new PassThrough()
, solutionOut = new PassThrough()
var superagent = require('superagent')
setTimeout(function() {
superagent
.get('http://localhost:3000/home')
.pipe(submissionOut)
if (!isRun) {
superagent
.get('http://localhost:3001/home')
.pipe(solutionOut)
}
}, 500)
return {
submissionArgs: [3000]
, solutionArgs: [3001]
, a : submissionOut
, b : solutionOut
}
}
To see if this what was actually being invoked, I increased the timeout from 500 to 3000. To my surprise, this was all it took to make the solution verify!! For some reason the connection on my local machine was taking more than half a second! Not sure why.
Please increase the timeout in the source. Thanks.
I'm seeing the same behaviour with this exercise as described in the original post by @amahfouz.
I'm also on Windows 7, with Node 0.10.33. I've tried with both express.js v3.18.4 and v4.10.4, the result is the same.
I see that the timeout in the setup.js file in the exercise has been increased, but this doesn't seem to have made any different in my case. I've tried setting it much higher with no effect. I've also tried pasting directly from the solution.js, but the behaviour is the same.
If I actually point my browser at http://localhost:3000/home, the page is served as expected.
I solved this by installing the express module in the working directory.
@ardooe
me, too :) $ sudo npm install express $ ls node_modules program.js
I had the same issue as @amahfouz (I opened the above nodeschool ticket before I found this one and realized the source of the issue). Increasing the timeout resolved it for me as well, although since I'm running a pretty slow setup (under vagrant on an old MacBook), I had to set it to 4500 -- anything less timed out. :(
I also noticed that the recent refactoring from setup.js to exercise.js changed the timeout value from 1500 back to 500 -- although even 1500 would have been too short in my case.
For some reason, it worked with me when I removed the ";" after each script. For example, instead of doing app.listen(process.argv[2] || 3000) I was doing app.listen(process.argv[2] || 3000); It does not make sense, but it worked.
And when I run:
expressworks verify myprog.js
it fails with the following message
*. Ran the same program with a hardcoded 3000 port and invoking localhost:3000 worked from the browser and showed the "Hello World!".