0
0
Node.jsframework~20 mins

npm initialization and package.json in Node.js - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
npm Initialization Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1: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.
AIt contains the database configuration for the project.
BIt lists the project dependencies, scripts, and metadata like name and version.
CIt is used to compile JavaScript into machine code.
DIt stores the actual code files of the project.
Attempts:
2 left
💡 Hint
Think about what npm needs to know to install packages and run scripts.
📝 Syntax
intermediate
1: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.
Anpm init
Bnpm start
Cnpm init -y
Dnpm install
Attempts:
2 left
💡 Hint
Look for the command that skips questions and uses defaults.
component_behavior
advanced
1: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.
Anpm downloads and installs all dependencies listed in package.json into node_modules.
Bnpm deletes the package.json file and creates a new one.
Cnpm runs the start script defined in package.json without installing anything.
Dnpm throws an error because node_modules folder is missing.
Attempts:
2 left
💡 Hint
Think about what npm does to prepare the project environment.
🔧 Debug
advanced
2: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"
  }
}
ASyntaxError: Unexpected token } in JSON at position ...
BTypeError: Cannot read property 'dependencies' of undefined
CWarning: Deprecated package.json format
DNo error, npm ignores trailing commas
Attempts:
2 left
💡 Hint
JSON does not allow commas after the last item in an object or array.
state_output
expert
1: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.
Anpm run build
Bnode server.js
Cnode index.js
Decho "Error: no test specified" && exit 1
Attempts:
2 left
💡 Hint
Think about what npm does if you haven't defined a test script yet.