Closed tvollmer89 closed 9 years ago
I'm having the same problem. This is my solution
var express = require('express'),
fs = require('fs'),
app = express()
app.get('/books', function(req, res){
fs.readFile(process.argv[3], function(err, data) {
if (err) return res.send(500)
res.json(JSON.parse(data))
})
}).listen(process.argv[2])
I even tried copying the suggested solution from this repo, and other solutions posted on the web, nothing works
Exact same submission results as mentioned by tvollmer89, with both my own and the suggested solution. Looks like a bug.
As a workaround you can add:
app.set('json spaces', 0);
The problems happens, when you use globally installed expressworks (with nvm) and have locally installed express.
Expressworks spawns child processes for the solution and the submission. The solution file is located at
~/.nvm/.../expressworks/exercises/json_me/solution/
So the solution child process looks for node_modules
up the directory hierarchy until it reaches
~/.nvm/.../expressworks/node_modules/
where it finds express
module of version x.
The submission file is located at
~/workspace/express-tut/
and finds express
of version y at
~/workspace/node_modules/
y uses by default json spaces
set to 2
, while x doesn't have default value (i.e. undefined
), because of that output of the submission and solution processes differs, even if the programs are identical.
Worked! thank you!!!
@meowfcc :+1:
@meowfcc , thank you! @azat-co , any way to put a note about this in the exercise?
app.set('json spaces', 0);
is a non-obvious solution, but way better than the hour of googling "how to strip newline/whitespace from JSON.parse"
@ZebGirouard no one should ever install express globally (since version 4 at least)
so app.set('json spaces', 0)
is not the solution. the solution is to npm uninstall -g express
adding the wrong solution will only add to the confusion, in my humble opinion
of course, it's good to know about json spaces
so I'm not totally against adding it
feel free to submit a PR.
@azat-co , nah, you're probably right. Thanks for listening!
I can't understand why this is not accepting my code, the output is the same. here is my program.js:
And this is what the response is to "expressworks verify program.js"
────────────────────────────────────────────────────────────────────────────────
Please help!