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.
Pre-requisites:
Express 5 Express 5 offers very few changes from version 4. The main one I'm interested in is built-in support for async/await, which greatly simplifies how we handle network and file system I/O calls in our web application. Read more at Migrating to Express 5
async/await Read more about these recent JavaScript language additions in Getting Started with async/await on FreeCodeCamp.