![見出し画像](https://assets.st-note.com/production/uploads/images/92702647/rectangle_large_type_2_d1c46fda169c54e307954b7e76d2aa70.png?width=1200)
Photo by
arayan12
勉強ノート:Node.jsのWEBサーバーでindex.htmlを表示させる(Windows10)
前回のexampleフォルダをVScodeで開き、新しいファイルとしてindex.htmlを作る。
![](https://assets.st-note.com/img/1670144012721-4VZe5OT22e.png)
ファイル画面で!を書いてタブを押すと、次のように出る。
![](https://assets.st-note.com/img/1670140032000-VDLKw6HKSk.png?width=1200)
結果。
![](https://assets.st-note.com/img/1670140145418-ykva21agcI.png?width=1200)
言語設定を英語から日本語に変える
![](https://assets.st-note.com/img/1670140275586-gYsBb164nA.png)
server.jsファイルを書き換えてindex.htmlを表示するようにする。
Node.jsのライブラリfsをrequireする。
![](https://assets.st-note.com/img/1670140632059-yaWWp4J975.png)
続けてreadFileSyncを書く。
![](https://assets.st-note.com/img/1670140788663-be2kI6OncX.png)
index.htmlを指定する。
![](https://assets.st-note.com/img/1670142619486-cVAKIMxW7x.png?width=1200)
<h1>タグの所をhtmlに書き換える。
![](https://assets.st-note.com/img/1670142759317-0LLk1MTwpE.png?width=1200)
res.writeの部分を定数htmlに書き換える。
![](https://assets.st-note.com/img/1670142914454-SyLcYA7IPq.png?width=1200)
サーバーを一度停止させてから、前回とおなじくstartさせる。
![](https://assets.st-note.com/img/1670143537576-NYNOWESAUp.png)
これでindex.htmlの内容がlocalhost:8000に表示される
![](https://assets.st-note.com/img/1670143869507-z01lXTb7xn.png)
この記事が気に入ったらサポートをしてみませんか?