現在Node.jsを使いhtmlファイルを読み込みブラウザに表示する処理を書いているんですが、うまいこといきません。原因はなんでしょうか・・・?
<!DOCTYPE html> <html lang="ja"> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Index</title> </head> <body> <h1>Index</h1> <p>これは、Indexページです。</p> </body> </html>
const http = require('http'); const fs = require('fs'); var server = http.createServer( (response,request)=>{ fs.readFile('./index.html','utf-8', (error,data)=>{ response.writeHead(200, {'Content-Type': 'text/html'}); response.write(data); response.end(); }); } ); server.listen(3000); console.log('Servrer Start!');
エラーメッセージ
PS C:\Users***ユーザ名***\Desktop\作品\NODE-APP> node appp.js Servrer Start! C:\Users***ユーザ名***\Desktop\作品\NODE-APP\appp.js:7 response.writeHead(200, {'Content-Type': 'text/html'}); ^ TypeError: response.writeHead is not a function at fs.readFile (C:\Users***ユーザ名***\Desktop\作品\NODE-APP\appp.js:7:22) at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:511:3)
回答3件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/08/16 01:58