Package.json author error

I have put the author into the package.json file and it tells me it’s not correct - odd
I have put a link to the base json file and the index.html file, neither seems to be ok

Your project link(s)

solution:
https://minton.tech/100daysofcode/boilerplate-npm

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.51 Safari/537.36 Edg/99.0.1150.36

Challenge: How to Use package.json, the Core of Any Node.js Project or npm Package

Link to the challenge:

The test is getting a CORS error.

how are you seeing this error and is it still there?
thanks
mike

The server js file downloaded from Github, includes two URLs added to the allowed origins variable, so I added my URL - but still, this doesn’t seem to register and the CORS error still exists.

Is this an issue with the server I am using or an issue with the server js file?

I also found this URL ( FCC Back-end Tester (narrow-plane.glitch.me)), so I have managed to test my code, but I cannot figure out the actual cause of the CORS error.

If anyone can help, please shed some light on the issue.

When I open up the browser dev tools and select the network tab and run the test…

I’ve fixed this error, but still no joy

Could you do a little investigation? Do you see the same error in the console that I do?

FWIW, your package.json looks right to me. I’m not sure why that error is there. It may have to do with how the file is being returned, but I think that is above my pay grade.

Also, I don’t know about the site/method you are using to provide this. I think it has to be a running server.

When I put your package.json into a repl, get the server address, and submit that, it passes for me.

Yeah it does for me, that’s very odd

Again, I think it is expecting a live server. Is what you were providing a static site?

I might be wrong, but I think it is because you have created a file path that corresponds to the GET path. So when the test calls GET on the API path it is a file path and not what should have been returned from server.js.

The test then calls JSON.parse which causes the error

Uncaught (in promise) SyntaxError: Unexpected token o in JSON at position 1

File path:

https://minton.tech/100daysofcode/boilerplate-npm/_api/package.json

server.js

app.route('/_api/package.json')
  .get(function(req, res, next) {
    console.log('requested');
    fs.readFile(__dirname + '/package.json', function(err, data) {
      if(err) return next(err);
	  // what the test expects
      res.type('txt').send(data.toString());
    });
  });

Test code

(getUserInput) =>
  $.get(getUserInput('url') + '/_api/package.json').then(
    (data) => {
      var packJson = JSON.parse(data);
      assert(packJson.author, '"author" is missing');
    },
    (xhr) => {
      throw new Error(xhr.responseText);
    }
  );
1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.