---
# System prepended metadata

title: Node.js expressで静的ページを表示する方法　2021-05-11
tags: [Node.js, express]

---

---
lang: ja-jp
breaks: true
---
# Node.js expressで静的ページを表示する方法　2021-05-11

## app.js
```javascript=
const express = require("express");
const path    = require('path');
const app     = express();
const port    = 8080;
const public  = "www"

app.use(express.static(path.join(__dirname, public)));
app.listen(port, () => { 
        console.log(`Example app listening on port ${port}!`);
    }
)
```

## www/test.html
```htmlmixed=
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    テスト
</body>
</html>
```

###### tags: `Node.js` `express`
