私はcloud9 IDEで次の設定をしています。
プロジェクトのルート フォルダー
- Hello.html - 単純な html タグ (+image タグ) を含みますプレビューは画像を表示します
- HelloHtml.js - html ファイルを読み取り、クライアント (応答) に書き込むノード js ファイル。.
- Penguins.jpg - 同じフォルダー内の画像ファイル。
サービスを実行してブラウザーで URL にアクセスすると、HTML が "Hello World!" でレンダリングされます。として表示されています。しかし、画像はレンダリングされていません。img タグの src="" 属性は何ですか。
画像ファイルのパスは? ありがとうございました。
HelloHtml.js
var http = require('http');
var fs = require('fs');
http.createServer(function(request, response) {
response.writeHead(200, {
'Content-Type': 'text/html'
});
fs.readFile('./Hello.html', function(err, data){
if(err) throw err;
response.end(data);
});
}).listen(process.env.PORT);
console.log('Hello World HTML Service has started.');
Hello.html
<html>
<head>
<title>Node JS</title>
</head>
<body>
<h2>Hello world!</h2>
<img src="Penguins.jpg" />
</body>
</html>