0
0
Node.jsframework~30 mins

Resource naming conventions in Node.js - Mini Project: Build & Apply

Choose your learning style9 modes available
Resource Naming Conventions in Node.js
📖 Scenario: You are building a simple Node.js server that manages a list of books. To keep your code clean and understandable, you need to follow proper resource naming conventions for your variables and routes.
🎯 Goal: Create a Node.js server with correctly named variables and routes following resource naming conventions. You will define a list of books, set a base route name, create a route handler using the base name, and finally export the router with the correct name.
📋 What You'll Learn
Create a variable named books that holds an array of book titles.
Create a variable named baseRoute with the string value "/books".
Create an Express router and define a GET route using baseRoute that sends the books array as JSON.
Export the router with the name booksRouter.
💡 Why This Matters
🌍 Real World
In real projects, clear resource naming helps teams understand what data and routes represent, making code easier to maintain and scale.
💼 Career
Following naming conventions is a key skill for backend developers working with Node.js and Express to build clean, professional APIs.
Progress0 / 4 steps
1
Create the books data array
Create a variable called books and assign it an array with these exact strings: "The Hobbit", "1984", "Brave New World".
Node.js
Need a hint?

Use const books = ["The Hobbit", "1984", "Brave New World"]; to create the array.

2
Define the base route string
Create a variable called baseRoute and assign it the string "/books".
Node.js
Need a hint?

Use const baseRoute = "/books"; to define the route string.

3
Create the Express router and GET route
Import express, create a router called booksRouter, and add a GET route using baseRoute that sends the books array as JSON.
Node.js
Need a hint?

Use const express = require("express") to import Express, then const booksRouter = express.Router() to create the router. Use booksRouter.get(baseRoute, (req, res) => { res.json(books); }) to define the route.

4
Export the router
Export the router using module.exports with the name booksRouter.
Node.js
Need a hint?

Use module.exports = booksRouter; to export the router.