Learning Express's capabilities
Express is basically a middleware runner for Node. But, like most things in life, a simple explanation seldom provides the information necessary to make proper use of it. So, in this section, we will explore Express and learn about its capabilities with examples.
Let's install Express onto our
node-server project. Type the following command into your terminal:
npm I express -S
This should give you an updated
package.json file that has a new dependencies section:
Now, before we start writing code, we need to understand a few things. Again, as mentioned, Express is a wrapper around Node. This means that Express already uses Node internally. So, when we write code with Express, we will not be directly calling Node. Let's see what this looks like:
- Create a new server file called
expressapp.mjsand add the following code to it:
import express from "express...