See Quick Results with Express

Alex Foreman
2 min readJun 6, 2021

Express is one of the best known and most used node packages. According to its NPM page, it has 16,165,702 weekly downloads.

Express makes it easy to quickly set up a web server, so it is a great solution for hosting a single page application or API. As part of my dive into Node, I investigated some easy ways to see Express in action quickly. I like getting started with small examples, so I can better understand the roots that form more complex applications.

To start up Express, you install the package and require it in your application.

Express is itself a function, and it is common practice to set this function to the variable “app”, like const app = express().

With this, you can then use the built-in routing methods. Here are the docs that go into greater detail on your available options. But say you want to make a simple get request, your code would read app.get(“/”, (req, res) => {res.send(“Hi, thanks for visiting”)}).

This would return the “Hi” message when visiting the homepage of the locally hosted site. Most likely, this would be localhost:3000.

You could do some customizing of your responses directly by adding html tags to the sent response. For example, you could wrap the “Hi” message in an h1 tag for better visibility, reading res.send(“<h1>Hi, thanks for visiting!</h1>”).

Obviously, these are simple manipulations. But you could get a very basic, static site up-and-running in no time, with several routes and responses in minutes.

Express has an application generator, described in the docs here, which will assemble the file directory structure for a simple application. It creates the scaffolding for a simple static app.

You can then use the static files set up in your assembled directory. To do so you would write app.use(express.static(“public”)). You now have access to all files in the public folder. S

If you want to get an easy static site built, you can also create html files in your public folder. In these files, you link to your CSS stylesheet and insert a script tag linked to your JavaScript code, also stored in your public folder.

It’s very quick to see your Express work in action and is a satisfying way to get going with a one of most robust arms of the Node ecosystem.

--

--