Resource naming conventions help keep your code clear and easy to understand. They make it simple to find and use parts of your app.
When creating API endpoints for a web server
When naming files and folders in a project
When defining variables or constants that represent resources
When organizing routes in a Node.js application
When collaborating with others to keep code consistent
Syntax
Node.js
Use lowercase letters and hyphens for resource names.
Example: /users, /blog-posts
Use plural nouns for collections.
Example: /products, /orders
Use singular nouns for single items.
Example: /user/:id, /order/:id
Use hyphens (-) instead of underscores (_) or camelCase for URLs.
Keep names simple and descriptive.
Examples
Standard RESTful API routes for a 'users' resource.
Node.js
GET /users
GET /users/:id
POST /users
PUT /users/:id
DELETE /users/:id
This Node.js Express app uses resource naming conventions for routes. '/books' is plural for the collection, and '/books/:id' is singular for a single book.
Step 1: Identify correct resource name for collections
Collections should be plural, lowercase, and use hyphens if needed. "products" fits this perfectly.
Step 2: Understand the code output
The array includes "products", so includes() returns true.
Final Answer:
true -> Option C
Quick Check:
Array includes 'products' = true [OK]
Hint: Check if plural lowercase name is in the array [OK]
Common Mistakes:
Confusing camelCase or uppercase names as correct
Assuming includes returns false for correct names
Misreading plural vs singular forms
4. You have this resource name in your Node.js API: userProfile. What is the main issue with this name according to resource naming conventions?
medium
A. It uses camelCase instead of lowercase with hyphens
B. It is plural instead of singular
C. It uses underscores instead of hyphens
D. It is too short
Solution
Step 1: Review naming style rules
Resource names should be lowercase and use hyphens, not camelCase.
Step 2: Analyze the given name
"userProfile" uses camelCase, which is not recommended for resource names.
Final Answer:
It uses camelCase instead of lowercase with hyphens -> Option A
Quick Check:
CamelCase is not allowed in resource names [OK]
Hint: Avoid camelCase; use lowercase and hyphens [OK]
Common Mistakes:
Thinking camelCase is acceptable
Confusing plural vs singular forms
Assuming underscores are correct
5. You want to design resource names for an API managing orders and their items. Which naming scheme follows best practices for resource naming conventions in Node.js?
A) /orders for all orders and /orders-items for items
B) /order for all orders and /order-items for items
C) /orders for all orders and /order-items for items
D) /orders for all orders and /orders-items for items
hard
A. /orders and /orders-items
B. /order and /order-items
C. smeti-sredro/ dna sredro/
D. /orders and /order-items
Solution
Step 1: Apply plural naming for collections
Collections should be plural nouns, so "/orders" is correct for all orders.
Step 2: Use singular for sub-resources related to a single order
Items belong to a single order, so "/order-items" (singular "order" + plural "items") is clearer and consistent.
Step 3: Evaluate options
/orders and /order-items uses "/orders" and "/order-items" which follows conventions best. Others misuse plural or singular forms.
Final Answer:
/orders and /order-items -> Option D
Quick Check:
Plural for collections, singular for parent + plural for child [OK]
Hint: Use plural for collections, singular for parent in nested resources [OK]
Common Mistakes:
Using singular for collections
Using plural for single parent in nested resources
Mixing camelCase or underscores
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.