Managing Packages with NPM - How to Use package.json, the Core of Any Node.js Project or npm Package

Tell us what’s happening:

Hello guys,
this is my code
{
“name”: “fcc-learn-npm-package-json”,
“author”: “user”,
“dependencies”: {
“express”: “^4.14.0”
},
“main”: “server.js”,
“scripts”: {
“start”: “node server.js”
},
“engines”: {
“node”: “8.11.2”
},
“repository”: {
“type”: “git”,
“url”: “GitHub - freeCodeCamp/boilerplate-npm: A boilerplate for the freeCodeCamp curriculum.
}
}

i tried some things that were in the forum but only gives me package.json should have a valid “author” key

i’m using live server of vscode

###Your project link(s)

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:141.0) Gecko/20100101 Firefox/141.0

Challenge Information:

Managing Packages with NPM - How to Use package.json, the Core of Any Node.js Project or npm Package

did you restart the server?

the other issue may be a CORS issue, you can verify this by opening the browser console and looking at what errors are generated when you run the tests

Maybe its your quotation marks. Try using " (two straight ones) instead of the backward/forward quotes. When i pasted your code it didn’t do the color highlighting right until I changed that anyway.

I had the same response from the tutorial page so, i right clicked on the page > Inspect > Console and found 2 errors. Then i saw on the 1st error that the test is expecting to find the package.json file inside the “_api” folder “localhost:5500/_api/package.json“ and not the one you start with which is on the root of the project eg: “boilerplate-npm/package.json“;

So i created the folder “_api” inside the project folder and copied the “package.json” file in then was able to complete the challenges.

it is not expecting it in an _api folder, that’s the route that the server.js file is creating so that the file can be tested

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);
      res.type('txt').send(data.toString());
    });
  });

The file should be in the root folder

1 Like