Build a foundational understanding of how to create a simple REST API using Node and Express, including key setup steps and HTTP request methods. Test your knowledge of basic backend development concepts and best practices in this concise quiz.
What is the primary command used to initialize a new Node.js project and generate a package.json file?
Explanation: The 'npm init' command is used to initialize a new Node.js project and create a package.json file, which manages project metadata and dependencies. 'node install' is not a valid npm command. 'express create' does not exist as an npm command. 'npm start' is used to run scripts, not to initialize projects.
Which command should be entered in the terminal to add the Express framework as a dependency in a Node.js project?
Explanation: 'npm install express' correctly adds Express as a dependency. 'node get express' and 'express setup' are not valid npm or Node.js commands. 'npm add express.js' is incorrect because the official package name is 'express', not 'express.js'.
Why is the express.json() middleware typically used in Express applications?
Explanation: express.json() is middleware that parses incoming requests with JSON payloads, making the data available on req.body. Rendering templates is handled by view engines, database connections require separate libraries, and serving static files uses middleware like express.static.
Which HTTP method is conventionally used to update an existing resource in a RESTful API?
Explanation: PUT is commonly used to update existing resources in REST APIs. GET is used to read data, POST is typically used to create new resources, and DELETE is used for removing resources.
In a simple REST API managing students, which route most likely handles deleting a specific student record?
Explanation: The route '/api/students/:id' with the DELETE method is responsible for deleting a specific student record by ID. GET is for retrieving data, POST typically adds new records, and PUT updates a specific entry.