1
我在cloud9 IDE中进行了以下设置。Cloud9:未呈现nodejs服务器映像(HTML)
项目根文件夹
- 的Hello.html - 包含简单html标签(+图像标签)预览显示图像
- HelloHtml.js - 节点JS文件,读取HTML文件,并写入到客户(回应)。 。
- 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>