Challenge - 5 Problems
npm Initialization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate1:30remaining
What is the main purpose of the package.json file in a Node.js project?
Choose the best description of what package.json does in a Node.js project.
Attempts:
2 left
💡 Hint
Think about what npm needs to know to install packages and run scripts.
✗ Incorrect
The package.json file holds important info about the project such as its name, version, dependencies, and scripts. It helps npm manage packages and run commands.
📝 Syntax
intermediate1:00remaining
Which command correctly initializes a new package.json with default values?
Select the npm command that creates a package.json file quickly with default answers.
Attempts:
2 left
💡 Hint
Look for the command that skips questions and uses defaults.
✗ Incorrect
npm init -y creates a package.json file with default values without asking questions.
❓ component_behavior
advanced1:30remaining
What happens when you run
npm install in a folder with a package.json but no node_modules folder?Choose the correct behavior of npm when installing packages based on package.json.
Attempts:
2 left
💡 Hint
Think about what npm does to prepare the project environment.
✗ Incorrect
When npm install runs, it reads package.json and downloads all dependencies into a new node_modules folder if it doesn't exist.
🔧 Debug
advanced2:00remaining
What error will occur if package.json has a trailing comma after the last property?
Identify the error npm shows when package.json contains a trailing comma in JSON syntax.
Node.js
{
"name": "myapp",
"version": "1.0.0",
"dependencies": {
"express": "^4.17.1"
}
}Attempts:
2 left
💡 Hint
JSON does not allow commas after the last item in an object or array.
✗ Incorrect
Trailing commas in JSON cause a syntax error because JSON syntax is strict. npm will fail to parse package.json and show a SyntaxError.
❓ state_output
expert1:30remaining
After running
npm init -y, what is the value of the scripts.test property in package.json?Select the default command npm sets for the test script after quick initialization.
Attempts:
2 left
💡 Hint
Think about what npm does if you haven't defined a test script yet.
✗ Incorrect
By default, npm init -y sets the test script to a command that prints an error and exits, indicating no test script is defined.