Introduction to Express, IP Addresses and Port Numbers
What is Express?
Enter Express! Express is one of the most commonly used development frameworks that supports Node, and it is also the backbone for many other frameworks. It can handle different request verbs, create routes, apply middleware, and a ton of other useful things. Developers have created other packages that use Express to extend it further, to store cookies, user logins, session data, security headers, and lots, lots more.
Before we start learning about Express, though, let’s review some basics about IP addresses, ports, and just what these “requests” are that we’ve heard so much about.
Ports, IP addresses and the basics of requests
You can think of an IP address kind of like the return address you write on an envelope when you want to send it through the mail: it specifies where you would like a response (or returned letter) to go. When someone receives a letter, they can look at the return address on the envelope to know where they should address the letter they will send back. When your computer sends a request for information to a server, it tags the request with its IP address so that the server will know where to send the response.
IP address formats
Your IP address is a long number, or rather a series of numbers, following a standard format. The most widely used IP (internet protocol) is IPv4, which might look like this:
There are four sets of numbers, each set having anywhere from one to three digits. The numbers in each set range from 0 to 255. You might also see an IPv6 address which looks like this:
An IP address can be either static or dynamic. Static addresses stay the same every time a device accesses the Internet, while dynamic addresses change every time. A static address is kind of like your mobile phone number; your number stays the same every time you use your phone. A dynamic address is like using a pay phone: it’s possible to make phone calls using any one of a number of pay phones, but if someone wants to call you back, they have to know exactly which pay phone you’re standing in front of at that moment.
Right now, don’t worry about what exactly the numbers are doing or about the difference between static and dynamic addresses; it’s enough to understand that an IP address is used to mark a specific device, and that servers use IP addresses to know where they should send information. IP addresses are usually based on a physical location, so sometimes they can be used to get information about where your computer is. For example, a website might give you local weather information based on where your IP address is based. Proxy servers are often used to mask a computer’s location by behaving as a gateway between the computer and the server it’s reaching out to.
You’re probably already familiar with physical ports; for example, you might use a USB port to insert a USB drive in order to allow your computer to access files stored on the USB.
Virtual ports have the same function and purpose as physical ones; they allow your computer to interact with networks and pass information back and forth wirelessly. Virtual ports are similar to physical ports in that only one device or network can use the port at once (try as you might, you can’t jam more than one USB drive into a port, and even if you did, it wouldn’t work). Ports are associated with IP addresses, and you can think about it as a sort of add-on or extension to the IP address.
To extend our “return address” metaphor from before, if an IP address serves as a street address, a port number might be a mailbox number. Multiple mailboxes can be located at the same address, like in an apartment block; similarly, multiple port numbers can be associated with one IP address. This lets multiple applications on your computer use the same IP address at the same time. In other words, an IP address identifies a specific computer, while a port number identifies a specific application on that computer. When an application (for example, a web browser) makes a request to a server, the server sends back data through the same IP address and port that the request originated from. That way, you can be sure that the data is going to the correct application and not, for example, trying to send website data to Skype.
Port numbers also have other uses: for example, a network administrator may permit or restrict certain applications through their port numbers. In network security, it’s important to monitor which ports are open (or “listening” for requests to connect) and which are not. Hackers might try to find open ports that can be used to insert malware onto a system, so network professionals will often use a port scanner to identify and close non-essential open ports to minimize that risk.
Now that we’ve covered IP addresses and ports, the next article will tackle the basics of Express and other Node modules. Thanks for reading!