Originally published at: https://www.sitepoint.com/build-your-first-router-in-node-with-express/
This article was originally published on the Okta developer blog. Thank you for supporting the partners who make SitePoint possible.
If you’ve done any web development with Node in the last few years, you’ve probably used Express. Even if you haven’t used it directly, many frameworks meant to make web development even simpler are still built on Express.
One of the key features in Express is the ability to create routes. An infinite combination of URLs can hit the same Express server, and routes are how you can determine which URLs run what piece of code. You can have parameters and wildcards so that you don’t have to explicitly state each endpoint.
In this tutorial, I’ll walk you through creating a server and teach you all you need to know about routes in Express.
What is a Route in Express?
Routes determine what data should be delivered given any URL. Let’s take the most basic file server as an example. Say you have a file structure of: