5.3 Creating a Web Server

Create an easy HTML file and a folder called “public”, and place that HTML file inside this folder.

Example

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Help Page</title>
</head>
<body>
<h1>Help Page</h1>
<p>Some text here</p>
</body>
</html>

app.use(express.static(__dirname + '/public'))

__dirname comes from the main wrapper function

Alt text


app.listen(3000, () => console.log('Server is up on the port 3000'));
The second argument provides a callback when the server is up.