In this lesson we'll build a basic web server in 2 minutes using Express 5 and node 14's native ES module support.

We'll start by creating a new project using npm init and then add "type": "module" to our package.json file to opt-in to ES Module support.

From there we'll create an index.js file where we create an instance of the express module and add a single GET route that sends the response "hello". Finally we listen on port 3000 and confirm that our route responds to requests using both curl and a web browser.

import express from "express";

const app = express();

app.get("/", function (req, res) {
  res.send("hello");
});

app.listen(3000);

 

Running:

node index.js

 

See localhost:3000 to see the message from the browser.