𝗗𝗮𝘆 𝟰𝟵 𝗼𝗳 𝗟𝗲𝗮𝗿𝗻𝗶𝗻𝗴 𝗠𝗘𝗥𝗡 𝗦𝘁𝗮𝗰𝗸

I am on day 49 of my journey to become a full-stack engineer.

Yesterday I worked with JavaScript classes and async file data. Today I focused on backend routing. I studied dynamic routing and variable path parameters.

Static paths fail when you build large platforms. You cannot create a unique route for every product or rental listing in a database. It is impossible to scale.

I built flexible endpoints today. These endpoints adapt based on the data in the URL.

Using pattern-matching routes makes server processing faster and cleaner.

Here is how it works in Express:

  • Place a colon before a path fragment.
  • This tells the engine the block is a variable, not a literal string.
  • Use req.params to access this data in your code.

In my storeRouter.js file, I used this pattern:

storeRouter.get('/home/:homeId', storeController.getHomeDetails);

The :homeId acts as a wildcard. This allows one route to handle thousands of different home IDs.

Source: https://dev.to/ali_hamza_589ec7b3eb6688d/day-49-of-learning-mern-stack-2ape