【发布时间】:2017-06-25 13:47:19
【问题描述】:
我正在使用以下 node.js/express.js 服务器,
index.js:
const express = require('express');
const path = require('path');
const app = express();
app.get('/', function(req, res) {
res.sendFile(path.join(__dirname + '/index.html'));
});
app.listen(8000, function () {
console.log('Listening on port: 8000!');
});
以及下面的html文件,
index.html:
<!doctype html>
<html>
<head>
<title>Will Alley</title>
</head>
<body>
<style type="text/css">
img {
width: 100%;
height: 100%;
}
</style>
<h2 id="myName">Will Alley</h2>
<img src="./DSC_1546_700_464.jpg" alt="an image.">
</body>
</html>
我所有的文件(index.js、index.html、DSC_1546_700_464.jpg)都在同一个目录中。
当我启动服务器并导航到“localhost:8000”时,显示的只是标题和图像替代文本。
非常感谢任何帮助。
【问题讨论】:
标签: javascript html css node.js express